[jdom-interest] detach() [eg]

Jason Hunter jhunter at acm.org
Wed Apr 25 11:00:47 PDT 2001


Brett McLaughlin wrote:
> 
> I'm with Elliotte that detach should not be on the Element, but on the
> Element's parent. 

We already have Element.removeContent().  If you're suggesting a new
method Document.detach(Element) or Document.removeContent(Element) then
it's no better than status quo because that call would still allow
non-well-formed documents.

Or is your argument that detach() should go away, that
Element.removeContent() should remain, and that Document should thus
have no way to detach its root short of the programmer substituting a
new root in place of the old with setRootElement()?  Ugh.

> I don't. What might make that "easier" makes it "Easier" for folks to create
> non-well-formed Documents. I thought that in recent mails, we weren't going
> to let non-well-formed things happen? 

Enforcing well-formed documents is a goal.  So is programmer
ease-of-use.  This is one place where they're in conflict.  There's no
easy answer, as evidenced by 50 emails on this subject.

> I guess we either need to say "we're
> schizophrenic, because we can be" (which is OK, I suppose), or say "we're
> always well-formed" and then this dicussion is moot. 

Let's say you want to take the root from doc A and add it to doc B.  I
don't think it's good to make the programmer do a.setRootElement(new
Element("bogus")) just to have the side effect that this detaches the
old root so you can now add it to B.

The lesser evil seems to be lazy enforcing of well-formedness in this
one area.

> Well, we enforce it in JDOM code. But you've let loose a Document object
> that doesn't have to have a root. So a client can mess what that all you
> want. Is calling getContent()/getMixedContent() going to throw an ISE? 

There's no getContent() but getMixedContent() would.

> What
> about getProcessingInstructions()? 

Nope.  But that method may be deprecated anyway.  :-)

> How long do you let a document be used
> when it's non-well-formed. 

Until you try to get something which should contain a root but doesn't.

> I think this is a much more slippery-slope than
> is being acknowledged so far.

We're on top of an ice mountain.

> Doesn't seem right to me, still. elt.clone() makes sense. elt.detach()
> doesn't - it doesn't fit into the nice tree model that everyone got fed to
> them in CS, doesn't fit into what people expect, IMO.

XML doesn't fit into the nice tree model.

-jh-



More information about the jdom-interest mailing list