[jdom-interest] getChildren() vs getElements()
Peter V. Gadjokov
pvg at c-c-s.com
Sat Sep 16 06:50:34 PDT 2000
Amy Lewis wrote:
> More than that, you lose any sense of relative location for all the
> child nodes, between nodes of different types. [...]
> So, while from a programming sense it is certainly *cleaner* to
> describe a tree of elements, it doesn't usefully describe the
> documents that the programmers are going to encounter, and isn't,
> therefore, a good abstraction.
"It's worse than that - he's dead, Jim!"
You're absolutely right, losing the document for non-elements won't cut it.
But is it really the case that the abstraction itself is bad? If I hadn't
stuffed my foot in my mouth by talking about implementation details in an
API design discussion, the abstraction described is essentially identical to
what we have now. Children are always elements. Everything else is something
else. To get the ordered-document-of-everything view, you use the List
accessors (the thing JDOM now calls content), to get the Element-centric
view, you use getChild/getChildren. Granted, this isn't what the XML
Infoset calls children. The argument for giving Elements the simple,
easy-to-use, Zen-compliant method names is based on the assumption that
Element-centric traversal of programmatically generated XML documents is
becoming as important and common a use-case as processing human-written,
document-annotation-style XML. Some (like Don Box and co) go as far as to
argue that the latter is going to eventually die out . Is this worth
using terminology that is simple, evokes the sound of one hand clapping but
is not 'spec-compliant'? I think so, but I'm biased, living largely in the
XML-as-RPC, element-centric, PI/Comment devoid world.
"...a tedious argument of insidious intent to lead you to an overwhelming
The two viable (i.e. consistent) approaches so far seem to be Alex's
proposal (call Elements elements and children children and possibly make
Jason live with something like getChildElementText[Trim]) and keeping things
(API-wise) as they are. I'd be happy with either as long as the change (if
any) is not piecemeal.
 _Essential XML : Beyond MarkUp_; Don Box, Aaron Skonnard, John Lam;
Addison-Wesley, 2000; ISBN: 0201709147
More information about the jdom-interest