php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53181 XPath bugs when selecting attributes with namespace
Submitted: 2010-10-27 11:54 UTC Modified: 2010-10-27 12:10 UTC
From: ivan dot enderlin at hoa-project dot net Assigned:
Status: Not a bug Package: *XML functions
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
28 + 11 = ?
Subscribe to this entry?

 
 [2010-10-27 11:54 UTC] ivan dot enderlin at hoa-project dot net
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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-27 12:10 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2010-10-27 12:10 UTC] pajoye@php.net
That's an issue in libxml2. PHP uses libxml2, but we don't develop it. No need to duplicate the entry.

Will ping one of the dev to see what's going on there.
 [2010-12-06 11:06 UTC] ivan dot enderlin at hoa-project dot net
Some news about libxml2 developers?
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed May 25 17:04:04 2022 UTC