From 6dc4be710088496d59c07e2b68a447b8ec4f0cd0 Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Wed, 10 Sep 2008 11:21:48 +0000 Subject: [PATCH] MFH: fix bug #45553 (Using XPath for attributes with a namespace does not work) add test --- ext/simplexml/simplexml.c | 2 +- ext/simplexml/tests/bug45553.phpt | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ext/simplexml/tests/bug45553.phpt diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 03320bf2ff..6f40566f63 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1229,7 +1229,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 -- 2.40.0