#42083 [Opn]: Attributes set in wrong namespace, and multiply defined
| From: | mail_ben_schmidt at yahoo dot com dot au | Date: | Tue, 24 Jul 2007 04:03:12 +0000 |
| Subject: | #42083 [Opn]: Attributes set in wrong namespace, and multiply defined | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115365@lists.php.net to get a copy of this message | ||
ID: 42083
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:
Also forgot to explicitly mention that the same attribute can also be
added twice using array notation, thereby generating invalid XML.
Previous Comments:
------------------------------------------------------------------------
[2007-07-24 03:17:34] mail_ben_schmidt at yahoo dot com dot au
Description:
------------
OK! This one really is a bug! I know it must be a bug as invalid XML is
produced that can't be parsed! I have also tried it with
php5.2-200707181030, though just running the binary in sapi/cli/php
rather than doing make install.
When attributes are set or added using array notation, this is not done
according to the currently active scope of the SimpleXMLElement in use.
Deletion and access work as expected, however. Thus a newly
added/modified attribute cannot then be deleted or accessed without
changing namespaces to the unnamed namespace by use of attributes().
Reproduce code:
---------------
$str=<<<DONE
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"
xmlns:ns="http://localhost/a">
<elem attr="abc"/>
<elem ns:attr="abc"/>
<ns:elem attr="abc"/>
<ns:elem ns:attr="abc"/>
</root>
DONE;
$xml =
simplexml_load_string($str,'SimpleXMLElement',0,'http://localhost/a');
foreach ($xml->children('http://localhost/a') as
$elem) {
unset($elem['attr']);
$elem['attr']="new";
$elem['attr']="three";
echo $elem['attr']."\n";
}
echo $xml->asXML();
Expected result:
----------------
three
three
three
three
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"
xmlns:ns="http://localhost/a">
<elem attr="abc" ns:attr="three"/>
<elem ns:attr="three"/>
<ns:elem attr="abc" ns:attr="three"/>
<ns:elem ns:attr="three"/>
</root>
Actual result:
--------------
[begins with four blank lines]
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"
xmlns:ns="http://localhost/a">
<elem attr="abc" attr="new" attr="three"/>
<elem attr="new" attr="three"/>
<ns:elem attr="abc" attr="new" attr="three"/>
<ns:elem attr="new" attr="three"/>
</root>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42083&edit=1