From: Operating system: PHP version: Irrelevant Package: *XML functions Bug Type: Bug Bug description:XPath bugs when selecting attributes with namespace
Description: ------------ XPath (and possibly libxml2) has a bug when selecting attributes with a namespace. We must use the namespace-uri() function to solve this problem whereas using a registered prefix does not work. A bug has been reported to Gnome in 2008: <https://bugzilla.gnome.org/show_bug.cgi?id=562557> but it's still opened and not resolved. Test script: --------------- <?php $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n\n" . '<foo xmlns="http://ns1" xmlns:x="http://ns2">' . "\n" . ' <bar a="b" x:c="d" e="f" g="h" />' . "\n" . '</foo>'; $sxe = simplexml_load_string($xml); $sxe->registerXPathNamespace('', 'http://ns1'); $sxe->registerXPathNamespace('x', 'http://ns2'); echo $xml . "\n\n" . 'â //@* found(' . count($sxe->xpath('//@*')) . ')' . "\n" . 'â //@x:* (x registered as http://ns2) found(' . count($sxe->xpath('//@x:*')) . ')' . "\n" . 'â //@*[namespace-uri() = "http://ns2"] found(' . count($sxe->xpath('//@*[namespace-uri() = "http://ns2"]')) . ')' . "\n"; Expected result: ---------------- <?xml version="1.0" encoding="utf-8"?> <foo xmlns="http://ns1" xmlns:x="http://ns2"> <bar a="b" x:c="d" e="f" g="h" /> </foo> â //@* found(4) â //@x:* (x registered as http://ns2) found(1) â //@*[namespace-uri() = "http://ns2"] found(1) Actual result: -------------- <?xml version="1.0" encoding="utf-8"?> <foo xmlns="http://ns1" xmlns:x="http://ns2"> <bar a="b" x:c="d" e="f" g="h" /> </foo> â //@* found(4) â //@x:* (x registered as http://ns2) found(4) â //@*[namespace-uri() = "http://ns2"] found(1) -- Edit bug report at http://bugs.php.net/bug.php?id=53181&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53181&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53181&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53181&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53181&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53181&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53181&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53181&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53181&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53181&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53181&r=support Expected behavior: http://bugs.php.net/fix.php?id=53181&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53181&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53181&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53181&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53181&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53181&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53181&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53181&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53181&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53181&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53181&r=mysqlcfg