PHP XML DOM Uncaught exception 'DOMException' with message 'Wrong Document Error' PHP XML DOM Uncaught exception 'DOMException' with message 'Wrong Document Error' xml xml

PHP XML DOM Uncaught exception 'DOMException' with message 'Wrong Document Error'


You need to import any node to append it to another document:

$departmentArray->item($i)->appendChild( $doc->importNode( $employee, true ) );


I'm pretty sure that this is happening because you are trying to append an element from a different document into your output document.

I found this code in a comment on php's site for DOMNode::cloneNode which might be what you want.

<?php     $dom1->documentElement->appendChild(         $dom1->importNode( $dom2->documentElement, true )    ); ?>

Alternatively, you could look at exporting the node's XML and reimporting it into a DOMDocumentFragment, but I'd have to experiment to know for sure.