[jdom-interest] setMixedContent()

Per Kreipke per at onclave.com
Fri May 18 13:52:39 PDT 2001

I'm trying this to make a copy of all the content within one element to
another element:

void copyContents(Element src, Element dest)

Given two elements with this schema:

<item author="...">

With the latest JDOM code, I get an exception:

org.jdom.IllegalAddException: The element "title" could not be added as a
child of "item": The element already has an existing parent "item"
	at org.jdom.Element.addContent(Element.java:1135)
	at org.jdom.Element.setMixedContent(Element.java:830)

What is it I should be doing?

- in the previous version of the function, the elements were copied but
parenting was left pointing at the previous parent

- Cloning the src element first would still leave all its content pointing
to the
clone and presumably still raise the exception.

- should setMixedContent() be detaching each node before moving it?

- should I clone the src, detach all the nodes within, then add them one by


More information about the jdom-interest mailing list