php.net |  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
Votes:2
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-01-12 01:14 UTC] 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>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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-2022 The PHP Group
All rights reserved.
Last updated: Sat Jan 22 21:03:35 2022 UTC