[jdom-interest] XML tree traversing

Jason Hunter jhunter at collab.net
Thu Dec 28 10:26:47 PST 2000

> Mores Stanislav wrote:
> Hi,
> I wondered why not to have simpler mean of XML tree traversing,
> by defining the following methods:
>   Element getFirstChild();              - returns first child element
> or null
>   Element getNextSibling();             - returns next sibling element
> or null
> and possibly:
>   Element getPrevSibling();

Might want to try getChildren().iterator().  Then you get the standard
Java Iterator behavior.  Or getMixedContent().iterator() if you want all
mixed content.

> That would be more easier to use than getChildren(),
> with no memory overhead (no List allocation),

You still have to allocate some data structure to track where you are
and keep track of modifications you might make.  It's best if we use the
standard Java Iterator data structure for that.

> especially when traversing the whole tree, which is my
> case ( I need to process each node in the tree).

If you want to process each item in the tree, you'd be better off
arguing for a document iterator/walker/traverser.  I'm trying to see if
we have a compelling use case for that (both to justify adding it, and
to make sure a solution solves those issues), so please, if you could,
explain your use case.


More information about the jdom-interest mailing list