ID:               42034
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mail_ben_schmidt at yahoo dot com dot au
-Status:           Open
+Status:           Bogus
 Bug Type:         SimpleXML related
 Operating System: Mac OS X
 PHP Version:      5CVS-2007-07-18 (snap)
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The attributes are accessed based on the namespace scope the
SimpleXMLElement object is currently in.


Previous Comments:
------------------------------------------------------------------------

[2007-07-18 16:15:16] mail_ben_schmidt at yahoo dot com dot au

Description:
------------
In SimpleXML, when deleting attributes via 'unset', attributes having
the same namespace as the element (or some such wrong namespace) are
deleted rather than the non-prefixed one which is the one actually
appearing in the 'array' (or not appearing--it can still be deleted if
it does not 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"/>
<elem ns:attr="abc"/>
<elem other:attr="abc"/>
<ns:elem attr="abc"/>
<ns:elem ns:attr="abc"/>
<ns:elem other:attr="abc"/>
<other:elem attr="abc"/>
<other:elem ns:attr="abc"/>
<other:elem other:attr="abc"/>
</root>
DONE;

$xml = simplexml_load_string($str);
foreach ($xml->elem as $elem) {
        unset($elem['attr']);
}
foreach ($xml->children('http://localhost/a')->elem as $elem) {
        unset($elem['attr']);
}
foreach ($xml->children('http://localhost/b')->elem as $elem) {
        unset($elem['attr']);
}
echo $xml->asXML();


Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";
xmlns:other="http://localhost/b";>
<elem/>
<elem ns:attr="abc"/>
<elem other:attr="abc"/>
<ns:elem/>
<ns:elem ns:attr="abc"/>
<ns:elem other:attr="abc"/>
<other:elem/>
<other:elem ns:attr="abc"/>
<other:elem other:attr="abc"/>
</root>


Actual result:
--------------
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";
xmlns:other="http://localhost/b";>
<elem/>
<elem/>
<elem other:attr="abc"/>
<ns:elem attr="abc"/>
<ns:elem/>
<ns:elem other:attr="abc"/>
<other:elem attr="abc"/>
<other:elem ns:attr="abc"/>
<other:elem/>
</root>



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42034&edit=1

Reply via email to