Req #2315 [Opn]: Adding getNodesAt in XML_Tree_Node
| From: | webmaster at enology dot dk | Date: | Sun, 12 Sep 2004 04:54:09 +0000 |
| Subject: | Req #2315 [Opn]: Adding getNodesAt in XML_Tree_Node | ||
| References: | 1 | Groups: | php.pear.webmaster |
| Request: | Send a blank email to pear-webmaster+get-3121@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=2315&edit=1
ID: 2315
User updated by: webmaster at enology dot dk
Reported By: webmaster at enology dot dk
Status: Open
Type: Feature/Change Request
Package: Web Site
Operating System: All
PHP Version: 4.3.2
New Comment:
Optimized a bit:
function &getNodesAt($path)
{
if (is_string($path)) $path = explode("/", $path);
if (count($path) == 0) return $this;
$path = array_shift($path);
// Get all children of this node whose name is '$next'
$childs = array();
if (is_array($this->children) && (count($this->children) > 0)) {
for ($i = 0; $i < count($this->children); $i++) {
if (($this->children[$i]->name == $path) &&
(!is_null($this->children[$i]))) $childs[] =& $this->children[$i];
}
}
return $childs;
}
Previous Comments:
------------------------------------------------------------------------
[2004-09-12 00:45:39] webmaster at enology dot dk
Description:
------------
PEAR Package: XML_Tree-2.0.0RC2
Adding function getNodesAt($path) in XML_Tree_Node so you're able to
get more nodes with same name.
Reproduce code:
---------------
/**
* Get references to nodes by its 'path'.
*
* @param mixed path Path to node. Can be either a string
(slash-separated
* children names) or an array (sequence of
children names) both
* starting from this node. The first name in
sequence is a child name, not the name of this node.
*
* @return object Reference to the XML_Tree_Node found, or
PEAR_Error if
* the path does not match any node.
* @access public
*/
function &getNodesAt($path)
{
if (is_string($path))
$path = explode("/", $path);
if (count($path) == 0) {
return $this;
}
$path1 = $path;
$next = array_shift($path1);
// Get all children of this node whose name is '$next'
$childs = array();
if (is_array($this->children) && (count($this->children) > 0)) {
for ($i = 0; $i < count($this->children); $i++) {
if (($this->children[$i]->name == $next) &&
(!is_null($this->children[$i]))) $childs[] =& $this->children[$i];
}
}
return $childs;
}
Expected result:
----------------
the return is an array with XML_Tree_Node objects in reference
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=2315&edit=1