[jdom-interest] detach() [eg]
Amy Lewis
amyzing at talsever.com
Tue Apr 17 15:44:17 PDT 2001
On Tue, Apr 17, 2001 at 02:18:42PM -0700, Jason Hunter wrote:
>Jools wrote:
>>
>> Whilst working through the source code for Element.java I became
>> uncomfortable
>> with the detach() method.
>>
<snip />
>>
>> Which means that if we detach a root element from Document it ends
>> up being a document with one root element <placeholder/>.
>>
>> Do we really want this, or should we simply set the root Element to
>> null ?
>
>If you set it to null then you have a malformed document. Every
>well-formed document has a root element. This was discussed earlier
>actually.
I've heard this argument, on this topic, before, but its repetition
fails to convince me.
There are a thousand or more ways to produce an ill-formed document
using JDOM. Hopefully, all of them are programmer errors, like
forgetting to add a root element to the document. I can't think of a
good excuse for shoehorning <a-random-element /> into the root
position, in defiance of the expectations of the programmer who just
emptied the document out *on purpose*, and I don't agree that
well-formedness is a sufficiently good excuse--certainly not as long as
one can add children to elements that do not belong there (JPanel,
java.sql.Connection, java.util.HashMap).
In other words, if we're going to enforce well-formedness, then we have
to enforce it (and in the process, take power and flexibility away from
the programmer; it always happens that if you dull a knife to keep it
from cutting someone's hands, it's harder to cut the bread). We have
to enforce it *everywhere*, and not just here, in a place where it's
easy.
Amy! (54 hours smoke free and probably not well-balanced at the moment;
excuse me if I am either babbling or overemphatic)
--
Amelia A. Lewis alicorn at mindspring.com amyzing at talsever.com
The flesh is strong. The spirit stronger. So shed your skin, baby.
Let it through. Come on over.
-- Amy Ray
More information about the jdom-interest
mailing list