PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » XML » XML_Tree » Bug #2315

Adding getNodesAt in XML_Tree_Node

Details

Request #2315Adding getNodesAt in XML_Tree_Node
Submitted2004-09-12 04:45 UTC
Fromwebmaster at enology dot dk
StatusSuspended
PackageXML_Tree
PHP Version4.3.2
OSAll
Roadmaps(Not assigned)

Comments

[2004-09-12 04:45 UTC] 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

[2004-09-12 04:54 UTC] webmaster at enology dot dk

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;
}

[2004-09-12 14:58 UTC] webmaster at enology dot dk

Changed to correct Package

[2006-05-29 16:25 UTC] webmaster at enology dot dk

OK, never mind..................

[2006-07-28 13:22 UTC] webmaster at enology dot dk

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz