From: sb1304 at hotmail dot com Operating system: Windows/Linux PHP version: 5.2.5 PHP Bug Type: DOM XML related Bug description: CreateAttributeNS incorrectly attaching to document element
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> -- Edit bug report at http://bugs.php.net/?id=43826&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43826&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43826&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43826&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43826&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43826&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43826&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43826&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43826&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43826&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43826&r=support Expected behavior: http://bugs.php.net/fix.php?id=43826&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43826&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43826&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43826&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43826&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43826&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43826&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43826&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43826&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43826&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43826&r=mysqlcfg