[jdom-interest] getChild() vs. getChildElements()

Brett McLaughlin brett.mclaughlin at lutris.com
Sun Jul 30 11:28:13 PDT 2000


  I'm very much against getChild() and getChildren(). Jason sort of
glossed over this (he's a Java guy purely, though, so I understand ;-)
), but it is absolutely the wrong name for a method that only returns
Elements. It is very clear from XML specs (XPath, XSLT, XPointer, pick
any of them...) that a child is not just an Element. Additionally, we
will continue to have lots of disillusioned DOM folks coming over, who
also (correctly) realize that a child can be anything... element,
entity, etc. So I'm very strongly against getChild(), getChildren(),
etc. It should very clearly be:


I know some folks think that shorter names are better, more convenient,
etc. This is just flat out wrong, I'm sorry to say, and not ever a good
reason to accept a name. We are coders - the next time someone complains
to me about having to type too much I'm going to throttle them (I'm only
partially kidding here). So I'm very strongly pushing a move to
getChildElement() and getChildElements(), as that is what the methods
do. I'm not going to put this in yet, but can almost guarantee it will
be in before beta 5. As a good reiteration, here's the text of an old
mail by Elliotte, which is right on target:

On a related note, I've been finishing up a medium-sized tutorial on 
JDOM to be given next Monday evening at XMLDevCon, and I find that I 
consistently misused getChildren() when what I really meant to do was 
getMixedContent().  I'm beginning to get used to it now, but I 
suspect this is a hurdle a lot of programmers are going to have to 
cross. I propose renaming all the getChildren() methods 
getChildElements() so there's no confusion. The various XML specs are 
all quite clear that elements aren't the only kind of children. 
Comments, processing instructions, and text nodes are children too. 
Only attributes are not children. 


Brett McLaughlin, Enhydra Strategist
Lutris Technologies, Inc. 
1200 Pacific Avenue, Suite 300 
Santa Cruz, CA 95060 USA 

More information about the jdom-interest mailing list