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: 2020-06-15 00:20 UTC
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: Duplicate Package: DOM XML related
PHP Version: 5.2.9 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-15 00:20 UTC] beberlei@php.net
-Status: Open +Status: Duplicate
 [2020-06-15 00:20 UTC] beberlei@php.net
Duplicate of 46185
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Aug 03 21:01:24 2020 UTC