[jdom-interest] Problem: element already has an existing parent
Kuehnberger
Kuehnberger at web.de
Mon Oct 22 00:39:37 PDT 2001
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
More information about the jdom-interest
mailing list