#45553 [Opn->Csd]: Using XPath to return values for attributes with a namespace does not work
| From: | rrichards@php.net | Date: | Wed, 10 Sep 2008 11:23:10 +0000 |
| Subject: | #45553 [Opn->Csd]: Using XPath to return values for attributes with a namespace does not work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-128838@lists.php.net to get a copy of this message | ||
ID: 45553
Updated by: rrichards@php.net
Reported By: njones at art-k-tec dot com
-Status: Open
+Status: Closed
Bug Type: SimpleXML related
Operating System: OSX
PHP Version: 5.2.6
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2008-07-18 11:07:09] njones at art-k-tec dot com
Description:
------------
Using XPath to return values for attributes with a namespace does not
work. It seems to be dropping any namespaces for attributes when using
XPath. But the namespace is clearly registered because it can be used to
access nodes, when using XPath.
Reproduce code:
---------------
$xml =<<<XML
<xml xmlns:a="http://a">
<data a:label="I am A" label="I am Nothing">test1</data>
<a:data a:label="I am a:A" label="I am a:Nothing">test2</a:data>
</xml>
XML;
$x = simplexml_load_string($xml);
$x->registerXPathNamespace("a", "http://a");
var_dump($x->xpath("/xml/data/@a:label"));
echo "<br /><br />";
var_dump($x->xpath("/xml/a:data"));
echo "<br /><br />";
var_dump($x->xpath("/xml/a:data/@a:label"));
echo "<br /><br />";
var_dump($x->data->attributes("http://a"));
Expected result:
----------------
array(1) { [0]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=>
array(1) { ["label"]=> string(12) "I am A" } } }
array(1) { [0]=> object(SimpleXMLElement)#2 (2) { ["@attributes"]=>
array(1) { ["label"]=> string(14) "I am a:Nothing" } [0]=> string(5)
"test2" } }
array(1) { [0]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=>
array(1) { ["label"]=> string(14) "I am a:A" } } }
object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(1) {
["label"]=> string(6) "I am A" } }
Actual result:
--------------
array(1) { [0]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=>
array(1) { ["label"]=> string(12) "I am Nothing" } } }
array(1) { [0]=> object(SimpleXMLElement)#2 (2) { ["@attributes"]=>
array(1) { ["label"]=> string(14) "I am a:Nothing" } [0]=> string(5)
"test2" } }
array(1) { [0]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=>
array(1) { ["label"]=> string(14) "I am a:Nothing" } } }
object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(1) {
["label"]=> string(6) "I am A" } }
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45553&edit=1