]> granicus.if.org Git - php/commitdiff
MFH: fix bug #45553 (Using XPath for attributes with a namespace does not work)
authorRob Richards <rrichards@php.net>
Wed, 10 Sep 2008 11:21:48 +0000 (11:21 +0000)
committerRob Richards <rrichards@php.net>
Wed, 10 Sep 2008 11:21:48 +0000 (11:21 +0000)
add test

ext/simplexml/simplexml.c
ext/simplexml/tests/bug45553.phpt [new file with mode: 0644]

index 03320bf2ffdea5f844704e3af1efcc199ac13415..6f40566f63bc07636f68aae11617fdcde403dd13 100644 (file)
@@ -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 (file)
index 0000000..37a46f4
--- /dev/null
@@ -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