From: Rob Richards Date: Wed, 10 Sep 2008 11:20:35 +0000 (+0000) Subject: fix bug #45553 (Using XPath for attributes with a namespace does not work) X-Git-Tag: BEFORE_HEAD_NS_CHANGE~446 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9068c264bedd081107863d4efa59042c763d86ee;p=php fix bug #45553 (Using XPath for attributes with a namespace does not work) add test --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 4e4c0a6283..b0d266072e 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1287,7 +1287,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-- + + test1 + test2 + +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