ID: 43826
User updated by: sb1304 at hotmail dot com
Reported By: sb1304 at hotmail dot com
Status: Open
Bug Type: DOM XML related
Operating System: Windows/Linux
PHP Version: 5.2.5
New Comment:
Apologies, ignore the comp->setAttributeNS... This should be commented
out. Was used for comparison test.
Previous Comments:
------------------------------------------------------------------------
[2008-01-12 01:14:07] sb1304 at hotmail dot com
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 this bug report at http://bugs.php.net/?id=43826&edit=1