Re: Combining 2 DOM XML nodes from different documents

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?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!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux