ID: 42083 Updated by: [EMAIL PROTECTED] Reported By: mail_ben_schmidt at yahoo dot com dot au -Status: Open +Status: Feedback Bug Type: SimpleXML related Operating System: Mac OS X PHP Version: 5.2CVS-2007-07-18 New Comment:
Where is it documented that you're allowed to modify the xml document like this? For me this just looks like abuse. Previous Comments: ------------------------------------------------------------------------ [2007-07-24 04:03:11] mail_ben_schmidt at yahoo dot com dot au Also forgot to explicitly mention that the same attribute can also be added twice using array notation, thereby generating invalid XML. ------------------------------------------------------------------------ [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