[XML-SIG] Filtering nodes from a DOM tree
Martin v. Loewis
Sun, 20 Jan 2002 10:32:06 +0100
> There are NodeIterator and TreeWalker classes in xml.dom, but looking
> at the code they don't seem to cope with the tree being modified while
> it's being traversed.
Can you give a specific example of what you think should work but
doesn't? From 18.104.22.168 of the DOM Traversal Range Specification:
# A NodeIterator [p.19] may be active while the data structure it
# navigates is being edited, so an iterator must behave gracefully in
# the face of change. Additions and removals in the underlying data
# structure do not invalidate a NodeIterator; in fact, a NodeIterator
# is never invalidated unless its detach() method is invoked. To make
# this possible, the iterator uses the reference node to maintain its
# position. The state of an iterator also depends on whether the
# iterator is positioned before or after the reference node.
# If changes to the iterated list do not remove the reference node,
# they do not affect the state of the NodeIterator [p.19] . For
# instance, the iterator s state is not affected by inserting new
# nodes in the vicinity of the iterator or removing nodes other than
# the reference node....
It may be the case that there are bugs in the implementation. Without
a specific example, it is hard to tell whether the problem is in 4DOM,
in DOM itself, in your application of the DOM, or whether the
Traversal APIs are simply not suited for what you want to achieve.