[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
<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/youraddr@yourhos
t.com
More information about the jdom-interest
mailing list