|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-08-14 12:12 UTC] chregu@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 14:00:01 2025 UTC |
An excerpt from DOM Level 2 Node::insertBefore: "If the newChild is already in the tree, it is first removed." In php 4.2.1 newChild is not removed from tree, it is only copied to the new location. Here is some sample code, $xml = <<<EOD <root> <Test> data to merge in parent bla bla <node>asdasd</node> </Test> <Treta> contents </Treta> </root> EOD; /* Move all children nodes to parent node of $fromNode. */ function MoveChildrenToParent($fromNode) { $parentNode = $fromNode->parent_node(); foreach ($fromNode->child_nodes() as $childNode) { //$fromNode->remove_child($childNode); // <-- uncomment this $parentNode->insert_before($childNode, $fromNode); } } $dom = domxml_open_mem($xml); $root = $dom->document_element(); $children = $root->child_nodes(); $testNode = $children[1]; MoveChildrenToParent($testNode); As you can see the children of Test node were not moved to root, they were copied. (uncomment the remove_child call from MoveChildrenToParent to see the right behavior)