[jdom-interest] Why should I have to detach()?

Steven D. Keens skeens at planetfred.com
Thu Mar 22 11:25:55 PST 2001

During one of my latest experiences with JDOM I got
an IllegalAddException when calling addContent( Element );

Not seeing any runtime exceptions declared in the docs I
went and looked at the code and found that
IllegalAddException is thrown when the new child element
already has a parent, when adding it to itselt or to a descendant.

I would like to know why?  Couldn't addContent() just detach
the new child element automatically from it's parent before
adding it?

The only reason I can see for doing that is to make
the user explicately aware that they are detaching
an element.  We had a similar structure in one of our
previous projects and we automatically detached the
child before changing its parent.  It was rarely
something that came up and bit us.

Steven Keens                mailto:skeens at planetfred.com
PlanetFred Inc.             http://www.planetfred.com
44 Byward Market, Suite 240, Ottawa, ON, K1N 7A2, Canada

More information about the jdom-interest mailing list