php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45553 Using XPath to return values for attributes with a namespace does not work
Submitted: 2008-07-18 11:07 UTC Modified: 2008-09-10 11:23 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: njones at art-k-tec dot com Assigned:
Status: Closed Package: SimpleXML related
PHP Version: 5.2.6 OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: njones at art-k-tec dot com
New email:
PHP Version: OS:

 

 [2008-07-18 11:07 UTC] 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" } }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-10 11:23 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: Tue May 07 17:01:33 2024 UTC