Home » XML » XML_Tree » Bug #555
getElementsByTagName uses non-existent property 'children'
Details
| Submitted | 2004-01-11 19:11 UTC |
|---|---|
| From | martinthomas1 at comcast dot net |
| Assigned | davey |
| Status | Closed |
| Package | XML_Tree |
| PHP Version | Irrelevant |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2004-01-11 19:11 UTC] martinthomas1 at comcast dot net
Description:
------------
The XML_Tree method getElementsByTagName attempts to use a
non-existent property children.
This property exists in XML_Tree_Node, not in XML_Tree.
PHP stops with the following error message:
<b>Notice</b>: Undefined property: children in <b>/vault/www/pear/lib/XML/Tree.php</b> on line <b>459</b><br />
Reproduce code:
---------------
<?php
$tree = &new XML_Tree();
$root= & $tree->addRoot('testdata');
$tree->insertChild('testdata','0','flywx', 'fly', array('wx2version'=>1));
print_r($tree->getElementsByTagName('flywx'));
?>
[2004-01-12 04:09 UTC] martinthomas1 at comcast dot net
If the function is examine children nodes (i.e. not all descendants) then the following works:
function &getElementsByTagName($tagName)
{
$thisroot = $this->getroot();
if (empty($tagName)) {
return $this->raiseError('Empty tag name');
}
if (sizeof($thisroot->children)==0) {
return null;
}
$result = array();
foreach ($thisroot->children as $child) {
if ($child->name == $tagName) {
$result[] = $child;
}
}
return $result;
}
[2004-05-15 18:46 UTC] M dot d dot m dot duijvestijn at hro dot nl
Maybe the GetElementsByTagName-function should be placed in the xml/node.php file in stead of the tree.php file?
I tried it that way, and then it works. The property "children" is inside that file as well, so it is not unlogical.