|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-12 01:18 UTC] sb1304 at hotmail dot com
[2008-07-17 23:47 UTC] jani@php.net
[2008-07-25 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 01:00:01 2025 UTC |
Description: ------------ Creating a Namespace attribute through CreateAttributeNS always attaches the namespace declaration to the root/ducumentElement even when the node is another one. Same issue whether there is a default Namespace or not. Same on Windows/Linux. SetAttributeNS performs as expected. Reproduce code: --------------- <?php $doc = new DOMDocument ("1.0", "utf-8"); $root = $doc->createElementNS("urn:ietf:params:xml:ns:epp-1.0",'employee'); $doc->appendChild($root); $name = $root->appendChild($doc->createElement("empname")); $name->appendChild($doc->createTextNode("test")); $addr = $root->appendChild($doc->createElement("empaddr")); $addr->appendChild($doc->createTextNode("test123")); $comp = $root->appendChild($doc->createElement("comp")); $comp->appendChild($doc->createTextNode("TEST LTD")); //Create a attribute with namespace $attr = $doc->createAttributeNS('ns','surname:prefix'); //append the new attribute node into the employee element $comp->appendChild($attr); //$root->setAttributeNS('ns', 'surname:prefix', 'none'); $comp->setAttributeNS('ns', 'surname:prefix', 'none'); //save the DOMDocument into a file $test = $doc->saveXML(); echo $test; ?> Expected result: ---------------- <?xml version="1.0" encoding="utf-8" ?> <employee xmlns="urn:ietf:params:xml:ns:epp-1.0"> <empname>test</empname> <empaddr>test123</empaddr> <comp xmlns:surname="ns" surname:prefix="">TEST LTD</comp> </employee> Actual result: -------------- <?xml version="1.0" encoding="utf-8" ?> <employee xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:surname="ns"> <empname>test</empname> <empaddr>test123</empaddr> <comp surname:prefix="">TEST LTD</comp> </employee>