[jdom-interest] Last call: getChild/getChildren versus getChildElement/getChildElements
Bradley S. Huffman
hip at cs.okstate.edu
Fri Feb 6 16:43:55 PST 2004
Elliotte Rusty Harold writes:
> At 2:26 PM -0600 2/6/04, Bradley S. Huffman wrote:
>
> >But one is just a very restrict case of the other, so why have 2 ways of
> >doing the same thing with two different interfaces when one consistent
> >inferace is all that's really need?
>
> The same reason you have any other convenience method: because it
> makes common operations a lot simpler.
Really? Using a little XOM code as an example, I find
for (int i = 0; i < element.getChildCount(); i++) {
Node child = element.getChild(i);
if (child instanceof Element) {
processElement(children.get(i));
}
}
just as easy as
Elements children = element.getChildElements();
for (int i = 0; i < children.size(); i++) {
processElement(children.get(i));
}
And is getChildElements("bar") in JDOM and XOM really more convenient
that dom4j Node.selectNodes("child::bar")? It isn't as powerfull. Is it
faster? Maybe/maybe not. Will that still be true next year? Agian maybe/maybe
not.
But again, this late in the game, this is all just a mental exercise.
Brad
More information about the jdom-interest
mailing list