php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47913 AppendNode can change the namespace of an element
Submitted: 2009-04-07 07:33 UTC Modified: -
Votes:4
Avg. Score:3.8 ± 0.8
Reproduced:3 of 4 (75.0%)
Same Version:1 (33.3%)
Same OS:3 (100.0%)
From: robin2008 at altruists dot org Assigned:
Status: Open Package: DOM XML related
PHP Version: 5.2.9 OS: Ubuntu
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: robin2008 at altruists dot org
New email:
PHP Version: OS:

 

 [2009-04-07 07:33 UTC] robin2008 at altruists dot org
Description:
------------
After appendChild, the namespace prefix gets lost, so it inherits the namepsace from the parent xmlns.

Reproduce code:
---------------
// PHP 5.2.* namespace bug - appendChild() changes the namespace

$aDOM= DOMDocument::loadXML('<f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o>');
echo 'Initial DOM is '.$aDOM->saveXML().chr(13);

$newNode= $aDOM->createElementNS(" http://friend2friend.net ", 'newnode');
$newNode->appendChild($aDOM->documentElement);
echo 'Appending the document Element to f2f:newnode, it all looks OK: '.chr(13).$aDOM->saveXML($newNode).chr(13).chr(13);

$aDOM->appendChild($newNode);
echo 'But adding <f2f:newnode> back as the documentElement changes a namespace '.$aDOM->saveXML();

Expected result:
----------------
Should keep the original namespace:
<newnode xmlns=" http://friend2friend.net " xmlns:default="default"><o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></o></newnode>


Actual result:
--------------
Loses the namespace prefix, so it inherits a different one the from xmlns of the parent node
<newnode xmlns=" http://friend2friend.net " xmlns:default="default"><o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><watch-me/></default:i></o></newnode>


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC