Bug #64254 [Opn->Fbk]: remove node and re-append, namespace is dropped.
Edit report at https://bugs.php.net/bug.php?id=64254&edit=1
ID: 64254
Updated by: mike@php.net
Reported by: chaced at gmail dot com
Summary: remove node and re-append, namespace is dropped.
-Status: Open
+Status: Feedback
Type: Bug
Package: DOM XML related
Operating System: Linux debian
PHP Version: 5.4.11
Block user comment: N
Private report: N
New Comment:
The namespaces equal, or do I miss anything?
Previous Comments:
------------------------------------------------------------------------
[2013-02-20 17:20:24] 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>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64254&edit=1
Thread (3 messages)