note 46636 modified in function.dom-domnode-clonenode by danbrown

From: Date: Fri, 28 Nov 2008 21:54:38 +0000
Subject: note 46636 modified in function.dom-domnode-clonenode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147278@lists.php.net to get a copy of this message
For those converting from PHP 4 DOM XML to PHP 5 DOM extension: In the old days, DOM XML's clone_node() was the way to copy nodes from one DOM to another, as well as to perform intra-DOM copies. Nowadays, DOM's cloneNode() is the intra-DOM solution, but see importNode() (http://php.net/dom-domdocument-importnode) to copy nodes from one DOM to another. So to append root node of $dom2 and all its children into root node of $dom1: PHP 4 (DOM XML): <?php $root1 = $dom1->document_element(); $other_node = $dom2->document_element(); $root1->append_child($other_node->clone_node(true)); ?> PHP 5 (DOM): <?php $dom1->documentElement->appendChild( $dom1->importNode($dom2->documentElement, true)); ?> --was-- For those converting from PHP 4 DOM XML to PHP 5 DOM extension: In the old days, DOM XML's clone_node() was the way to copy nodes from one DOM to another, as well as to perform intra-DOM copies. Nowadays, DOM's cloneNode() is the intra-DOM solution, but see importNode() (http://php.net/dom-domdocument-importnode) to copy nodes from one DOM to another. So to append root node of $dom2 and all its children into root node of $dom1: PHP 4 (DOM XML): <? $root1 = $dom1->document_element(); $other_node = $dom2->document_element(); $root1->append_child($other_node->clone_node(true)); ?> PHP 5 (DOM): <? $dom1->documentElement->appendChild( $dom1->importNode($dom2->documentElement, true)); ?> http://php.net/manual/en/function.dom-domnode-clonenode.php

« previous php.notes (#147278) next »