question: NodeIterator in DOM

Tyler Baker tyler at
Mon May 18 14:32:45 BST 1998

Akitoshi Yoshida wrote:

> Hi,
> Another question regarding NodeIterator:
> You have an NodeIterator instance with the iterator
> position set somewhere in the middle. When you
> remove three nodes: first, the node just after the
> iterator position, second the node after this removed
> node, and finally the node just before
> the original iterator position,
> then what should toNextNode() and toPrevNode() return?

Essentially a similiar problem occurs in the JDK 1.2 Collection classes.  What
JavaSoft suggests is that for all Iterators (a new interface in the JDK 1.2
Collection classes) you synchronize on the object being iterated so that no
internal changes to the object's state are made while iterating.  Since DOM is
supposed to be architectural and language neutral, languages which lack
synchronization support may find some difficulty in making sure that an object
which returns an Iterator object is not mutated while iteration is occurring in a
multithreaded environment.  If your application is single threaded, you should
not have to worry about your object (such as a List) that returns the Iterator
object being mutated except for programming error where you add and remove
objects to the object returning the Iterator object while iterating.  Sorry to be
so convoluted here but I got 3 hours of sleep last night so I hope the above made


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as:
To (un)subscribe, mailto:majordomo at the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list