How can I clone nodes between documents in PHP? [duplicate]
Possible Duplicate:
DOMElement cloning and appending: ‘Wrong Document Error’
I would like to copy all the child nodes of element foo
in DOMDocument
A into element bar
in DOMDocument
B. However, using appendChild
to do so apparently throws a DOM_WRONG_DOCUMENT_ERR
.
Is there a right way of doing this?
XML Document A
<foo>
<child 开发者_开发知识库/>
<child />
<child />
</foo>
XML Document B
<bar>
<other-child />
<other-child />
</bar>
Resulting DOMDocument
:
<bar>
<other-child />
<other-child />
<child />
<child />
<child />
</bar>
The elements should not be assumed to be empty, but are arbitrarily complex.
You will probably want to take a look at DOMDocument::importNode.
This function returns a copy of the node to import and associates it with the current document.
精彩评论