|  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: 2020-06-15 00:20 UTC
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: Duplicate 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.
Block user comment
Status: Assign to:
Bug Type:
From: robin2008 at altruists dot org
New email:
PHP Version: OS:


 [2009-04-07 07:33 UTC] robin2008 at altruists dot org
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=" " 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(" ", 'newnode');
echo 'Appending the document Element to f2f:newnode, it all looks OK: '.chr(13).$aDOM->saveXML($newNode).chr(13).chr(13);

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

Expected result:
Should keep the original namespace:
<newnode xmlns=" " xmlns:default="default"><o xmlns:f2f=" " 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=" " xmlns:default="default"><o xmlns:f2f=" " xmlns:default="default"><default:i xmlns="default"><watch-me/></default:i></o></newnode>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-15 00:20 UTC]
-Status: Open +Status: Duplicate
 [2020-06-15 00:20 UTC]
Duplicate of 46185
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 02:01:29 2024 UTC