The DocumentIterator object enables you to iterate over document elements in a specified document range. To accomplish this, create a new DocumentIterator instance and call its DocumentIterator.MoveNext method until it returns false. For each step, the current document element is obtained with the DocumentIterator.Current property.
This example creates a DocumentIterator instance for the current document and calls its DocumentIterator.MoveNext method to iterate over document elements. A Visitor pattern is implemented to process a document element. The implementation is done by calling each element's IDocumentElement.Accept method with the MyVisitor object instance as a parameter. MyVisitor object implements the IDocumentVisitor interface and overrides its IDocumentVisitor.Visit methods to perform required actions when an iterator encounters a certain document element ( an instance of the class inherited form the DocumentElementBase class).