|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-07-11 15:57 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
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>