How to add existing JDOM/DOM elements to a document object?

Roseanne Zhang

In JDOM, use (org.jdom.Element)org.jdom.Element.clone() will solve your problems. JDOM clone is a deep clone and it will forget its parent etc.

In DOM, you need to use

org.w3c.dom.Document.importNode(node, true)
to make the node forget its parent and switch the container Document.