Combining 2 DOM XML nodes from different documents
| From: | Eli | Date: | Thu, 01 Feb 2007 20:22:38 +0000 |
| Subject: | Combining 2 DOM XML nodes from different documents | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-248166@lists.php.net to get a copy of this message | ||
Hi,
<?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
How can I combine these 2 XMLs to get:
<a p1="v1">
<a1 p1="vv1"/>
<b p1="v1">
<b1 p1="vv1"/>
</b>
</a>
-thanks! :-)