[jdom-interest] Problem: element already has an existing parent

MarkW markw at wilsoncom.de
Mon Oct 22 03:17:53 PDT 2001


Hi,
try something like:
page2 = (Element)page.clone();

Mark

> -----Ursprungliche Nachricht-----
> Von: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]Im Auftrag von Kuehnberger
> Gesendet: Montag, 22. Oktober 2001 09:40
> An: jdom-interest at jdom.org
> Betreff: [jdom-interest] Problem: element already has an existing parent
> 
> 
> Hi I try to get an xml document like
> 
> <root>
>     <page>
>         <a>
>             <b>something1</b>
>             <b>something2</b>
>         </a>
>     </page>
>     <page>
>         ...
>     </page>
> </root>
> 
> where page must be dynamically set, when a condition applies.
> For that I tried something like
> 
> Document doc = null;
> Element root = new Element("root");
> Element page = new Element("page");
> Element a = new Element("a");
> while (b) {
>     Element b = new Element("b");
>     b.addContent("something");
>     a.addContent(b);
>     if (condition applies) {
>        page.addContent(a);
>        root.addElement(page);
>        a = new Element("a");
>        page = new Element("page");
>     }
> }
> 
> if try that, I get :
> The element "page" could not be added as a child of "root": The element
> already has an existing parent "root".
> 
> How can achieve something like that?
> 
> Jens
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yourad
dr at yourhost.com



More information about the jdom-interest mailing list