diff options
| -rw-r--r-- | ext/simplexml/simplexml.c | 2 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug45553.phpt | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 7c4809cec3..d8345a3626 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1270,7 +1270,7 @@ SXE_METHOD(xpath) if (nodeptr->type == XML_TEXT_NODE) { _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC); } else if (nodeptr->type == XML_ATTRIBUTE_NODE) { - _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_ATTRLIST, (char*)nodeptr->name, NULL, 0 TSRMLS_CC); + _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_ATTRLIST, (char*)nodeptr->name, nodeptr->ns ? nodeptr->ns->href : NULL, 0 TSRMLS_CC); } else { _node_as_zval(sxe, nodeptr, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC); } diff --git a/ext/simplexml/tests/bug45553.phpt b/ext/simplexml/tests/bug45553.phpt new file mode 100644 index 0000000000..37a46f4276 --- /dev/null +++ b/ext/simplexml/tests/bug45553.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #45553 (Using XPath to return values for attributes with a namespace does not work) +--FILE-- +<?php +$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"); + +$atts = $x->xpath("/xml/data/@a:label"); +echo $atts[0] . "\n"; +$atts = $x->xpath("/xml/a:data"); +echo $atts[0]->attributes() . "\n"; +$atts = $x->xpath("/xml/a:data/@a:label"); +echo $atts[0] . "\n"; +$atts = $x->xpath("/xml/a:data/@label"); +echo $atts[0] . "\n"; +$atts = $x->xpath("/xml/data/@label"); +echo $atts[0] . "\n"; +?> +--EXPECTF-- +I am A +I am a:Nothing +I am a:A +I am a:Nothing +I am Nothing
\ No newline at end of file |
