PHP XML DOM Uncaught exception 'DOMException' with message 'Wrong Document Error'
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.