Re: Robustness of root node in traversal

Joseph Kesselman wrote:

> > The DOM2 Traversal spec defines very well what should happen
> > if the currentNode of a nodeIterator or treeWalker is moved
> > in a document or out from it. However what should happen if
> > the root node is moved in the tree?
>
> Or the root's ancestor. The answer in either case is basically "nothing
> happens."
>
> NodeIterator operates only within, and upon, the root node's subtree.
> Moving the root has no effect on the structure of the subtree, and hence
> has no effect upon iteration.
>
> TreeWalker operates as pure-current-node semantics. The root acts as a
> fence preventing us from traversing out of it. (Actually, it's more like a
> one-way gate; if you setCurrentNode to someplace outside the root you
could
> traverse back into the root but can't traverse out again.) Again, moving
> the root has absolutely no effect if currentNode is within the root's
> subtree (since the subtree moves with the root). If you've previously
> created the odd outside-the-root condition, moving the root just changes
> where the recapture will occur.
>
> This seemed fairly obvious to the Traversal team, so we didn't state it
> explicitly. Does it really need to be nailed down?

For the treeWalker I agree it's rather obvious, however for the nodeIterator
I would say that it wouldn't hurt with some nailing. The reason is that
implementation-wise this introduces two different behaviours for for the
reference node when an ancesor is moved out from the tree:
1. If the removed node is between the reference node and the rootnode the
reference node is moved up in the tree.
2. If the removed node is root node or an ancestor to it the referenced node
is unaffected.

But section 1.1.1.2 says "If the reference node is removed from the list
being iterated over, a different node is selected as the reference node"
which isn't entierly correct.

/ Jonas Sicking

Received on Monday, 21 May 2001 10:20:59 UTC