Req #2315 [NEW]: Adding getNodesAt in XML_Tree_Node
| From: | webmaster at enology dot dk | Date: | Sun, 12 Sep 2004 04:45:39 +0000 |
| Subject: | Req #2315 [NEW]: Adding getNodesAt in XML_Tree_Node | ||
| Groups: | php.pear.webmaster | ||
| Request: | Send a blank email to pear-webmaster+get-3120@lists.php.net to get a copy of this message | ||
From: webmaster at enology dot dk
Operating system: All
PHP version: 4.3.2
Package: Web Site
Bug Type: Feature/Change Request
Bug description: Adding getNodesAt in XML_Tree_Node
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 bug report at http://pear.php.net/bugs/bug.php?id=2315&edit=1
--