php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64254 remove node and re-append, namespace is dropped.
Submitted: 2013-02-20 17:20 UTC Modified: 2014-12-30 10:41 UTC
From: chaced at gmail dot com Assigned:
Status: No Feedback Package: DOM XML related
PHP Version: 5.4.11 OS: Linux debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
4 + 17 = ?
Subscribe to this entry?

 
 [2013-02-20 17:20 UTC] chaced at gmail dot com
Description:
------------
A node has a namespace, remove this node, stock node into an array, and add this 
node, the namespace is dropped.




Test script:
---------------
<?php
function test($xml) {
	$dom = new DomDocument();
	$dom->loadXML($xml);
	$node = $dom->documentElement;
	$nodes = array();
	foreach($node->childNodes as $n) if($n->nodeType==XML_ELEMENT_NODE) $nodes[]=$n;
	foreach($nodes as $n) $n->parentNode->removeChild($n);
	foreach($nodes as $n) $node->appendChild($n);
	echo $dom->saveXML();
}

test('<?xml version="1.0" encoding="UTF-8"?><test xmlns:any="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"><item /><item xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"/></test>');
test('<?xml version="1.0" encoding="UTF-8"?><test xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"><item /><item xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"/></test>');

Expected result:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:any="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"><item/><item 
xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"/></test>
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"><item/><item 
xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"/></test>


Actual result:
--------------
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:any="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"><item/>
<any:item/></test>
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"><item/><item/>
</test>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-02 16:29 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2013-12-02 16:29 UTC] mike@php.net
The namespaces equal, or do I miss anything?
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Sep 28 15:01:25 2023 UTC