#17771 [Opn->Csd]: insert_before misbeaviour (DOM L2 spec.)
| From: | chregu@php.net | Date: | Wed, 14 Aug 2002 16:12:36 +0000 |
| Subject: | #17771 [Opn->Csd]: insert_before misbeaviour (DOM L2 spec.) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16790@lists.php.net to get a copy of this message | ||
ID: 17771
Updated by: chregu@php.net
Reported By: rui@ruilopes.com
-Status: Open
+Status: Closed
Bug Type: DOM XML related
Operating System: Win2k
PHP Version: 4.2.1
New Comment:
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a
documentation
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2002-06-15 08:08:33] rui@ruilopes.com
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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17771&edit=1