[jdom-interest] get number of children

Jools Enticknap jools at jools.org
Wed Jan 17 06:58:42 PST 2001


> how can i know the number of children in an element or in the root.
> (without using getChildren as list, then use list.size())

I'm afraid that's the only way you can find out how many children are in
an Element.
 
> and can i reference an element by it's index/number without giving the name:
> something like elem.getchild(0) will bring me the first child in the elem
> element

getChildren() returns a List. The List interface has a method called
get(int index)
which you can use if you need random access to the list. However if you
simply
wish to iterate through the list, an Iterator is more efficient.

The Element itself does not provide this functionality.

--Jools



More information about the jdom-interest mailing list