[jdom-interest] detach() [eg]

Amy Lewis amyzing at talsever.com
Thu Apr 19 12:59:55 PDT 2001

On Thu, Apr 19, 2001 at 01:12:31PM -0500, philip.nelson at omniresources.com wrote:
>> philip.nelson at omniresources.com wrote:
>> > 
>> > What if we had getRootElement() throw an 
>> Illegal<something>Exception when
>> > the placeholder was there?  Then it wouln't matter at all 
>> how the internal
>> > state was kept.  Other than to see if you have this bogus 
>> Document, I can't
>> > see any valid reason you would want to get the root 
>> element.  If you try to
>> > output the document, you would get a meaningful error.  If 
>> you can't be
>> > sure, you can attempt to get the root element and use a try 
>> catch to do the
>> > right thing.  Meanwhile, everything else works exactly the same way.
>> > Element.MISSING_ROOT_ELEMENT would have the meaningful text 
>> to use in the
>> > exception and could be protected an it's presence gives you 
>> a nice location
>> > to document the behaviour.
>> I like this idea.  Is it consistent though with our goal that 
>> JDOM docs
>> in memory are well-formed?  We'd have well-formed, or malformed but
>> you'll get an exception when you try something with them.  Hmm...
>I think internally we could leave the placeholder there.  This way, for
>internal uses the Document is still well formed.  The net effect is that we
>go from well formed but meaningless to well formed, meaningless with
>notification to the user if they don't deal with it.
>Mostly, from this discusion thread I was thinking about a system where a lot
>of documents pass through.  Without some kind of error, I could potentially
>not even know about the problem until I had erroneously saved documents that
>were perfectly well formed AND totally useless :-)

The more I think about this, the more I dislike the placeholder.

If the goal is to require the user to replace the root element, rather
than removing, then adding a new root element, then detach() should
*fail*.  It should *not* fail silently, adding random nonsense.

As it currently stands, it is possible to imagine an application in
which (for some reason), the code-path-less-taken resulted in a failure
to insert the new root element.  There would be no report of error, and
unless the bit above was implemented (which seems to me too little, too
late), then one could perfectly happily create a multi-megabyte
document containing any number of elements, none of which are where
they ought to be (because the root is <placeholder /> or

I propose, as an alternative, that to give some *life* and *action* to
the API, that we go *all-out* and name the root element that we're
inserting in the document behind the programmer's back by capturing the
output of fortune -s and replacing the spaces with underscores. 
Equally meaningful, useful, and predictable, but a lot more amusing to

Amelia A. Lewis         alicorn at mindspring.com           amyzing at talsever.com
A joke, that.  Love was the problem, not the solution.  Being hit by a car
was better than love.
		-- Steven Brust, PJF, "Cowboy Feng's Space Bar and Grille"

More information about the jdom-interest mailing list