[jdom-interest] (no subject)

zongo46 at gmx.net zongo46 at gmx.net
Tue Jun 12 10:53:58 PDT 2007


i also found another solution:

// get content of root element
List content = doc1.getRootElement().cloneContent();

cloneContent() instead of getContent() does it. you don't have to detach then.

thanks!
-------- Original-Nachricht --------
Datum: Tue, 12 Jun 2007 09:57:55 -0700
Von: Sonja Vrcic <sonja.vrcic at nrc.gc.ca>
An: zongo46 at gmx.net
Betreff: Re: [jdom-interest] (no subject)

> Try this:
> 
> // detach:
> int size = content.size();
> for(int i=0;i<size;i++){
>     Content next = (Content)content.get(0);
>     next.detach();
> }
> 
> Sonja
> 
> zongo46 at gmx.net wrote:
> 
> > 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!
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >To control your jdom-interest membership:
> >http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> >
> 
> -- 
> Sonja Vrcic
> Software Engineer
> National Research Council
> Herzberg Institute of Astrophysics
> Dominion Radio Astrophysical Observatory,
> Penticton, BC, Canada
> Tel:(250)490-4309/(250)493-2277ext.309
> Sonja.Vrcic at nrc-cnrc.gc.ca
> http://www.drao-ofr.hia-iha.nrc-cnrc.gc.ca/
> 

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser


More information about the jdom-interest mailing list