From:             njones at art-k-tec dot com
Operating system: OSX
PHP version:      5.2.6
PHP Bug Type:     SimpleXML related
Bug description:  Using XPath to return values for attributes with a namespace 
does not work

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 bug report at http://bugs.php.net/?id=45553&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=45553&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=45553&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=45553&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45553&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=45553&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45553&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45553&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45553&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45553&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45553&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=45553&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=45553&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45553&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45553&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45553&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45553&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45553&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45553&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45553&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45553&r=mysqlcfg

Reply via email to