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

Mark Bennett mbennett at ideaeng.com
Mon Oct 22 09:17:28 PDT 2001

I think you want to add a b.detach(); right after you create it.

-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
Behalf Of Kuehnberger
Sent: Monday, October 22, 2001 12:40 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Problem: element already has an existing parent

Hi I try to get an xml document like


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");
    if (condition applies) {
       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?


To control your jdom-interest membership:

More information about the jdom-interest mailing list