[jdom-interest] (no subject)
zongo46 at gmx.net
zongo46 at gmx.net
Tue Jun 12 01:06:46 PDT 2007
hi all,
i would like to add the content of a document's root element to the root
element of another document. here is my attempt:
> // create the document
> SAXBuilder builder = new SAXBuilder();
> Document doc1 = builder.build(new StringReader
> ("<elem>test<e2></e2><t/></elem>"));
>
> // get content of root element
> List content = doc1.getRootElement().getContent();
>
> // detach: --> same exception with or without this
> for(int i=0;i<=content.size();i++){
> Content next = (Content)content.get(i);
> next.detach();
> }
>
> // create 2nd document with root element
> Document doc2 = new Document();
> doc2.setRootElement(new Element("root2"));
>
> // add content to new root: Exception here
> doc2.getRootElement().setContent(content);
Exception in thread "main" org.jdom.IllegalAddException: The Content
already has an existing parent "elem"
detaching all Contents in the list does not seem to have an effect.
how can i solve this?
thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20070612/1b9faec8/attachment.htm
More information about the jdom-interest
mailing list