ID: 41861 Updated by: [EMAIL PROTECTED] Reported By: hubert dot roksor at gmail dot com -Status: Open +Status: Assigned Bug Type: SimpleXML related PHP Version: 5CVS-2007-06-30 (CVS) -Assigned To: +Assigned To: rrichards
Previous Comments: ------------------------------------------------------------------------ [2007-06-30 17:12:02] hubert dot roksor at gmail dot com Description: ------------ In addition to a node's own namespaces, getNamespaces() seems to return the namespaces of its latter siblings. In the reproduce code below, we create a tree composed of 5 nodes: the first and last nodes have no namespaces and the 3 nodes in-between each have their own namespace. We observe that getNamespaces() returns all 3 namespaces for the first node, altough it should have none, then 3, 2, 1 namespaces for the subsequent nodes (which should only have one each) then finally no namespace for the last node, as expected. children(), on the other hand, behaves correctly and does not find the nodes under those "extra" namespaces so I guess the problem is located in getNamespaces(). Thanks for reading :] Tested on: PHP 5.2.4-dev (cli) (built: Jun 30 2007 12:04:20) WinXP libxml2 2.6.26 SimpleXML Revision: 1.151.2.22.2.29 PHP 5.2.2-pl1-gentoo (cli) (built: May 24 2007 00:26:35) libxml 2.6.27 SimpleXML Revision: 1.151.2.22.2.26 Reproduce code: --------------- $xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8" ?> <root> <first_node_no_ns /> <ns1:node1 xmlns:ns1="#ns1" /> <ns2:node2 xmlns:ns2="#ns2" /> <ns3:node3 xmlns:ns3="#ns3" /> <last_node_no_ns /> </root>'); foreach (array(null, '#ns1', '#ns2', '#ns3') as $ns) { foreach ($xml->children($ns) as $child) { $name = $child->getName(); $namespaces = $child->getNamespaces(false); echo "children($ns) has found '$name' -- Its namespaces: ", implode(', ', $namespaces), "\n"; } } Expected result: ---------------- children() has found 'first_node_no_ns' -- Its namespaces: #ns1, #ns2, #ns3 children() has found 'last_node_no_ns' -- Its namespaces: children(#ns1) has found 'node1' -- Its namespaces: #ns1, #ns2, #ns3 children(#ns2) has found 'node2' -- Its namespaces: #ns2, #ns3 children(#ns3) has found 'node3' -- Its namespaces: #ns3 Actual result: -------------- children() has found 'first_node_no_ns' -- Its namespaces: children() has found 'last_node_no_ns' -- Its namespaces: children(#ns1) has found 'node1' -- Its namespaces: #ns1 children(#ns2) has found 'node2' -- Its namespaces: #ns2 children(#ns3) has found 'node3' -- Its namespaces: #ns3 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41861&edit=1