[jdom-interest] hasMixedContent()

Rosen, Alex arosen at silverstream.com
Mon May 14 12:04:11 PDT 2001


The getMixedContent() method has always bothered me a little, because it's a
misnomer. Mixed content means that an element can contain both text and child
elements. It says nothing about comments, for example - both mixed-content
elements and non-mixed-content elements can contain comments. Yet the only want
to obtain those comments is by using getMixedContent(), even if I know the
element can't really have mixed content. But, I just think of getChildren() as
really meaning getElementChildren(), and getMixedContent() as really meaning
getAllChildren(), and I'm OK with it. getMixedContent() returns the mixed
content, plus some extra bonus stuff, which isn't terrible.

But then I noticed hasMixedContent(). I have a bigger problem with this,
because it can return true even when the element does not have mixed content
according to the XML spec (e.g. because it contains only Strings and CDATAs, or
only Elements and Comments). This is just wrong.

It doesn't even match getMixedContent(). It's possible for hasMixedContent() to
return true even when getText() will give you all the element's contents
(because it contains Strings and CDATAs), or for it to return false when you
can only get all the contents by calling getMixedContent() (because it contains
only Comments). Seems like a useless method to me.

Does this bother anyone else? How should we fix it? Ideally, I'd like to make
name changes similar to the ones mentioned above, so that the method names say
what they really mean. (We are building a Java standard, after all.) Barring
that, we could just get rid of hasMixedContent(), unless anyone can come up
with a reason why it's useful.

Alex Rosen
SilverStream Software



More information about the jdom-interest mailing list