|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchessimplexml.c.patch (last revision 2011-04-26 23:07 UTC by tom at samplonius dot org)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-03-24 22:54 UTC] felipe@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: rrichards
[2014-07-01 14:55 UTC] giacomo at boticca dot com
[2014-07-03 06:58 UTC] rrichards@php.net
-Status: Assigned
+Status: Not a bug
[2014-07-03 06:58 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 09:00:01 2025 UTC |
Description: ------------ There are two issues: (1) If you addChild(), the new child always inherits the namespace of the parent. It is currently impossible to add children with no namespace, to a parent with a namespace. Though looking at the code, it is clear that is intent to distinguish between a NULL namespace value and a blank namespace value. I believe the design intent was that NULL means inherit the parent's namespace, and '' means that no namespace should be used. The attached patch does this. (2) If you specify a namespace of "", addChild() will actually add an attribute of " xmlns="" ", which is not valid. Patch is attached. If the $namespace parameter is "", no namespace is used, which fixes both issues. Test script: --------------- <?php header('Content-Type: text/plain'); $r = new SimpleXMLElement('<r />'); $c1 = $r->addChild('ns1:child1', NULL, 'urn:myspace1'); $c1->addChild('child2'); echo $r->asXML(), "\n"; $r = new SimpleXMLElement('<r />'); $r->addChild('Thing1', 100, ''); echo $r->asXML(), "\n"; Expected result: ---------------- <?xml version="1.0"?> <r><ns1:child1 xmlns:ns1="urn:myspace1"><ns1:child2/></ns1:child1></r> <?xml version="1.0"?> <r><Thing1>100</Thing1></r> Actual result: -------------- <?xml version="1.0"?> <r><ns1:child1 xmlns:ns1="urn:myspace1"><ns1:child2/></ns1:child1></r> <?xml version="1.0"?> <r><Thing1 xmlns="">100</Thing1></r>