note 46636 deleted from domnode.clonenode by joey
| From: | joey@php.net | Date: | Tue, 16 Oct 2012 01:02:42 +0000 |
| Subject: | note 46636 deleted from domnode.clonenode by joey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191316@lists.php.net to get a copy of this message | ||
Note Submitter: dtorop932 at hotmail dot com
----
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));
?>