ID: 41955 Updated by: [EMAIL PROTECTED] Reported By: hubert dot roksor at gmail dot com -Status: Open +Status: Assigned Bug Type: SimpleXML related PHP Version: 5CVS-2007-07-10 (snap) -Assigned To: +Assigned To: rrichards
Previous Comments: ------------------------------------------------------------------------ [2007-07-10 20:53:48] hubert dot roksor at gmail dot com Description: ------------ When adding a non-namespaced element to namespaced one, the new element is created under its parent's namespace instead of the scope's default namespace. In the reproduce code below we create a tree whose root element carries an empty default namespace declaration, with one "child" element under a custom namespace. We use addChild() to add a grandchild with no namespace defined. As per my understanding of XML Namespaces specifications, that element should be created under the default namespace and since the default namespace is empty the element should not use any namespace at all. A few notes: - moving the default namespace declaration to the child node does not change the outcome - using a non-empty default namespace does not change the outcome - specifying an empty namespace using addChild()'s third parameter gives the expected result Tested on: PHP 5.2.4-dev (cli) (built: Jul 10 2007 12:04:20) libXML Version => 2.6.26 SimpleXML Revision => $Revision: 1.151.2.22.2.33 $ Thanks for reading, and thanks for fixing my previous bugs so quickly ;) Reproduce code: --------------- <?php $xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?> <root xmlns:myns="http://myns" xmlns=""> <myns:child /> </root>'); $children = $xml->children('http://myns'); $children[0]->addChild('grandchild', 'hello'); echo $xml->asXML(); ?> Expected result: ---------------- <?xml version="1.0" encoding="utf-8"?> <root xmlns:myns="http://myns" xmlns=""> <myns:child><grandchild>hello</grandchild></myns:child> </root> Actual result: -------------- <?xml version="1.0" encoding="utf-8"?> <root xmlns:myns="http://myns" xmlns=""> <myns:child><myns:grandchild>hello</myns:grandchild></myns:child> </root> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41955&edit=1