xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arnaud Le Hors <leh...@us.ibm.com>
Subject Re: NodeIterator vs TreeWalker
Date Thu, 30 Nov 2000 20:32:15 GMT
> Dane Foster wrote:
> Can someone explain to me exactly what the difference is between a
> NodeIterator and a TreeWalker.  I have read the W3C's definition of
> the two so that is not what I'm looking for.  I've even written test
> code to see what the results of iterating over an XML fragment with a
> NodeIterator compared to a TreeWalker would return.  The returned the
> same exact results.

This was posted almost a month ago but I haven't seen any real answer so
here I go:

Although you can get the same result from the two in some cases there is
a fundamental difference between the two: NodeIterators do not point to
any node in the document but instead *between* two nodes. The idea is
that the iterator is a like cursor in the document tree. As nodes are
removed or added to the document the iterator says where it is in the
document. Just like your insertion cursor in a text editor stays in the
text even when you add or remove text around.
TreeWalkers on the other hand directly points to a specific node in the
tree. If the node being pointed to is moved around the TreeWalker will
follow. If the node being pointed to is removed from the tree, the
TreeWalker will follow too, effectively ending up outside the document
But of course if you're not mutating the tree at all they end up being
quite similar...

Hope this helps.
Arnaud  Le Hors - IBM Cupertino, XML Technology Group

View raw message