[jdom-interest] detach() [eg]

Joseph Bowbeer jozart at csi.com
Fri Apr 20 01:54:51 PDT 2001


> Yes, it's ugly to have a root replacement added.
> It's also ugly to break the well-formedness contract.
> Which one's less ugly?

I think the placeholder is uglier.

Do we have to tie the presence of a root Element to the well-formedness
contract?

After all, checking for a root Element is a really easy thing for the client
to do, and this chore could easily fall under the standard argument checking
done by any client.

For example, it'd be easy for XMLOutputter to throw an
IllegalArgumentException if the Document did not have an associated root
Element.

On the other hand, I can imagine that some clients might (like to) *require*
that their input Document *not* already have a root.  These would be builder
clients whose job it was to add Elements to a Document.

> Note you can't really have a root element with no
> associated document.  If there's no doc, it's not
> a root element, it's just an element.

I should have said you can detach the root Element from its Document, but
you can't detach the Document from its root.


----- Original Message -----
From: "Jason Hunter" <jhunter at collab.net>
To: "Joseph Bowbeer" <jozart at csi.com>
Cc: <jdom-interest at jdom.org>
Sent: Friday, April 20, 2001 1:04 AM
Subject: Re: [jdom-interest] detach() [eg]


Joseph Bowbeer wrote:
>
> I wonder, too.
>
> Adding a place-holder may preserve the well-formedness of the document,
> but it probably doesn't preserve the validity.
>
> If we can have root Elements with no associated Document and non-root
> Elements with no parent, what's so bad about Documents without roots?

Under the current design, what a developer can trust is:  Any JDOM
Document is a well-formed document, and any JDOM Element is a
well-formed document fragment.  So if you're writing an outputter or doc
manipulator, you know you don't have to check any well-formedness.
It'll be checked for you.

Note you can't really have a root element with no associated document.
If there's no doc, it's not a root element, it's just an element.

Yes, it's ugly to have a root replacement added.  It's also ugly to
break the well-formedness contract.  Which one's less ugly?

-jh-





More information about the jdom-interest mailing list