Re: (no subject)
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> An: [email protected] 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 > > [email protected] 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/[email protected] > > > > -- > 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 > [email protected] > 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 _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/[email protected]