<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head></head><body style="">
<font face="Verdana, Arial" size="2">hi all,<br>i would like to add the content of a document's root element to the root element of another document. here is my attempt:</font><br><blockquote><font face="Verdana, Arial" size="2"><font face="Verdana, Arial" size="1"></font></font><pre><font face="Verdana, Arial" size="2"><font size="2">                        // create the document<br>                        SAXBuilder builder = new SAXBuilder();<br>                        Document doc1 = builder.build(new StringReader ("&lt;elem&gt;test&lt;e2&gt;&lt;/e2&gt;&lt;t/&gt;&lt;/elem&gt;"));<br> <br>                        // get content of root element<br>                        List content = doc1.getRootElement().getContent();<br> <br>                        // detach: --&gt; same exception with or without this<br>                        for(int i=0;i&lt;=content.size();i++){<br>                                Content next = (Content)content.get(i);<br>                                next.detach();<br>                        }<br> <br>                        // create 2nd document with root element<br>                        Document doc2 = new Document();<br>                        doc2.setRootElement(new Element("root2"));<br> <br>                        // add content to new root: Exception here<br>                        doc2.getRootElement().setContent(content); </font></font></pre></blockquote><font face="Verdana, Arial" size="2"> <br>Exception in thread "main" org.jdom.IllegalAddException: The Content already has an existing parent "elem"<br> <br>detaching all Contents in the list does not seem to have an effect.<br><br>how can i solve this?<br>thank you!</font><br></body></html>