JDOM is an open source Java-based document object model for XML that was designed specifically for the Java platform so that it can access, manipulate, and output XML data. JDOM integrates with Document Object Model(DOM) and Simple API for XML (SAX), supports XPath and XSLT. It uses external parsers to build documents. It has been part of the Java Community Process as JSR 102, though that effort has since been abandoned. Its interface is very simple to use, and yet it’s very fast.
Error messgae: org.jdom.IllegalAddException: The Content already has an existing parent “root” or joining Xml Documents with RootElement’s
You just need to detach() the element from its parent before you insert it in another document. In JDOM implementation each element get link to parent: before you add an element in a new destination, you have to detach element from original structure.
Element elemCopy = (Element)element.clone(); elemCopy.detach(); destination.addContent(elemCopy);