[jdom-interest] Last call: getChild/getChildren versus getChildElement/getChildElements

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Feb 6 07:58:09 PST 2004

At 6:28 PM -0800 2/5/04, Jason Hunter wrote:

>Yes, but the child axis still has elements as the principal node 
>type, which is why $foo/child::bar returns bar elements and not bar 
>PIs.  Thus getChildren("bar") can be justified to return bar 

getChildren("bar") I agree, but getChildren() only returning elements 
is wrong, wrong, wrong. Did I mention it was wrong? It is 
inconsistent with the usage of the word "children" in the XML 1.0 
Recommendation.  It is inconsistent with the usage of children in 
DOM. It is brutally inconsistent with the definition of the children 
property in the XML Infoset:

[children] An ordered list of child information items, in document 
order. This list contains element, processing instruction, unexpanded 
entity reference, character, and comment information items, one for 
each element, processing instruction, reference to an unprocessed 
external entity, data character, and comment appearing immediately 
within the current element. If the element is empty, this list has no 

The method does not do what XML knowledgeable developers expect. It 
is confusing in both directions. Programmers who know XML will expect 
it returns all the children, not just the elements. Programmers who 
start with JDOM will learn this mistaken usage of the word children, 
and get confused when they use other technologies like XPath or 
XQuery that do not share this notion of children. This needs to be 
fixed now.

We've been around this circle before. We could (and should) have 
fixed it years ago. But we keep pussy-footing around, worrying about 
it the very temporary pain that will be caused if we change it. It's 
still broken. It still needs to be fixed. Fix it now, once and for 
all, and forget about it. Rip the band-aid off in one fell swoop. It 
will hurt a lot less to do that now than to spend the next ten years 
living with the ugly sore of this inconsistency.

   Elliotte Rusty Harold
   elharo at metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)

More information about the jdom-interest mailing list