php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41861 getNamespaces() returns the namespaces of a node's siblings
Submitted: 2007-06-30 17:12 UTC Modified: 2007-07-03 15:03 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: hubert dot roksor at gmail dot com Assigned: rrichards (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5CVS-2007-06-30 (CVS) OS:
Private report: No CVE-ID: None
 [2007-06-30 17:12 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-03 15:03 UTC] rrichards@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC