Re: Combining 2 DOM XML nodes from different documents

From: Date: Fri, 02 Feb 2007 03:07:52 +0000
Subject: Re: Combining 2 DOM XML nodes from different documents
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-248181@lists.php.net to get a copy of this message
<?php $x1 = <<<EOT <a p1="v1">
    <a1 p1="vv1"/>
</a> EOT; $x2 = <<<EOT <b p1="v1">
    <b1 p1="vv1"/>
</b> EOT; $X1 = new DOMDocument(); $X1->loadXML($x1); $X2 = new DOMDocument(); $X2->loadXML($x2); $X1->firstChild->appendChild($X2->firstChild->cloneNode(true)); echo htmlspecialchars($X1->saveXML()); ?> I got an error in the line $X1->firstChild->appendChild... [01-Feb-2007 22:20:29] PHP Fatal error: Uncaught exception 'DOMException' with message 'Wrong Document Error' in E:\www\mysite\htdocs\combine.php:17
Found the answer. Should use DOMDocument->importNode() method, and just append the imported node. -thanks!

« previous php.general (#248181) next »