|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43826 CreateAttributeNS incorrectly attaching to document element
Submitted: 2008-01-12 01:14 UTC Modified: 2008-07-25 01:00 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: sb1304 at hotmail dot com Assigned:
Status: No Feedback Package: DOM XML related
PHP Version: 5.2.5 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: sb1304 at hotmail dot com
New email:
PHP Version: OS:


 [2008-01-12 01:14 UTC] sb1304 at hotmail dot com
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:
$doc = new DOMDocument ("1.0", "utf-8");
$root = $doc->createElementNS("urn:ietf:params:xml:ns:epp-1.0",'employee');
$name = $root->appendChild($doc->createElement("empname"));
$addr = $root->appendChild($doc->createElement("empaddr"));
$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

//$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">
  <comp xmlns:surname="ns" surname:prefix="">TEST LTD</comp> 

Actual result:
<?xml version="1.0" encoding="utf-8" ?> 
 <employee xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:surname="ns">
  <comp surname:prefix="">TEST LTD</comp> 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-12 01:18 UTC] sb1304 at hotmail dot com
Apologies, ignore the comp->setAttributeNS... This should be commented out. Was used for comparison test.
 [2008-07-25 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 01:01:28 2024 UTC