[jdom-interest] detach() [eg]

Scott Means smeans at moonlightideas.com
Thu Apr 26 08:06:29 PDT 2001

OK, since I haven't written a lick of code for y'all (yet), I promise I
won't beat this particular horse anymore. But here is one more take on the
whole detach() thing.

The only conceivable reason to detach the root element of a document is
that I want to "harvest" it for use in another document. If I wanted to use
it in the existing document, I wouldn't have anyplace to hang it anymore
(since the document has no elements.) How about extending the addContent()
method like this:

Document addContent(Document document)

I know that there is a lot more to a document than the root element, but
what this could do is harvest the root element, set it to null, and
otherwise return the document to the same state it was after an empty
constructor. It's dead, and can't be used anymore. Believe it or not, I've
already encountered this particular case on my very first JDOM application,
and did the bogus element hack. I think it would have been friendlier to

 newDocument = null;

OK, shutting up now.

Scott Means (smeans at moonlightideas.com)

More information about the jdom-interest mailing list