#42026 [Opn]: Incorrect handling of default namespaces
| From: | mail_ben_schmidt at yahoo dot com dot au | Date: | Wed, 18 Jul 2007 11:12:23 +0000 |
| Subject: | #42026 [Opn]: Incorrect handling of default namespaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115171@lists.php.net to get a copy of this message | ||
ID: 42026
User updated by: mail_ben_schmidt at yahoo dot com dot au
Reported By: mail_ben_schmidt at yahoo dot com dot au
Status: Open
Bug Type: SimpleXML related
Operating System: Mac OS X
PHP Version: 5.2.3
New Comment:
Irrelevant to the bug itself, but one of my numbers that were meant to
be helpful in the code example was wrong. Should have read:
<other:elem attr="abc"/>1
<other:elem ns:attr="abc"/>0
<other:elem other:attr="abc"/>1
Previous Comments:
------------------------------------------------------------------------
[2007-07-18 11:09:01] mail_ben_schmidt at yahoo dot com dot au
Description:
------------
When getting children/attributes without using methods to specify a
namespace explicity, non-prefixed names are returned, but not prefixed
ones, even if the prefixed names are in the same namespace.
(Note that in fixing this bug there is a subtlety: the default
namespace for attributes is inherited from the element in which they
appear.)
Reproduce code:
---------------
$str=<<<DONE
<?xml version="1.0" encoding="utf-8"?>
<root
xmlns="http://localhost/a"
xmlns:ns="http://localhost/a"
xmlns:other="http://localhost/b"
>
<elem attr="abc"/>1
<elem ns:attr="abc"/>1
<elem other:attr="abc"/>0
<ns:elem attr="abc"/>1
<ns:elem ns:attr="abc"/>1
<ns:elem other:attr="abc"/>0
<other:elem attr="abc"/>0
<other:elem ns:attr="abc"/>0
<other:elem other:attr="abc"/>1
</root>
DONE;
$xml = simplexml_load_string($str);
foreach ($xml->elem as $elem) {
echo count($elem->attributes());
}
echo "\n";
foreach ($xml->children('http://localhost/a')->elem as $elem) {
echo count($elem->attributes());
}
echo "\n";
foreach ($xml->children('http://localhost/b')->elem as $elem) {
echo count($elem->attributes());
}
echo "\n";
Expected result:
----------------
110110 110110 101
Actual result:
--------------
100 100100 100
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42026&edit=1