Bug #47913 [Opn->Dup]: AppendNode can change the namespace of an element

From: Date: Mon, 15 Jun 2020 00:20:29 +0000
Subject: Bug #47913 [Opn->Dup]: AppendNode can change the namespace of an element
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227482@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=47913&edit=1 ID: 47913 Updated by: beberlei@php.net Reported by: robin2008 at altruists dot org Summary: AppendNode can change the namespace of an element -Status: Open +Status: Duplicate Type: Bug Package: DOM XML related Operating System: Ubuntu PHP Version: 5.2.9 Block user comment: N Private report: N New Comment: Duplicate of 46185 Previous Comments: ------------------------------------------------------------------------ [2009-04-07 07:33:00] 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> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=47913&edit=1

« previous php.bugs (#227482) next »