1 //------------------------------------------------------------------------------
2 // <copyright file="TreeIterator.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8 #pragma warning disable 618 // ignore obsolete warning about XmlDataDocument
10 using System.Diagnostics;
12 // Iterates over non-attribute nodes
13 internal sealed class TreeIterator : BaseTreeIterator {
14 private XmlNode nodeTop;
15 private XmlNode currentNode;
17 internal TreeIterator( XmlNode nodeTop ) : base( ((XmlDataDocument)(nodeTop.OwnerDocument)).Mapper ) {
18 Debug.Assert( nodeTop != null );
19 this.nodeTop = nodeTop;
20 this.currentNode = nodeTop;
23 internal override void Reset() {
24 currentNode = nodeTop;
27 internal override XmlNode CurrentNode {
33 internal override bool Next() {
36 // Try to move to the first child
37 nextNode = currentNode.FirstChild;
39 // No children, try next sibling
40 if ( nextNode != null ) {
41 currentNode = nextNode;
47 internal override bool NextRight() {
48 // Make sure we do not get past the nodeTop if we call NextRight on a just initialized iterator and nodeTop has no children
49 if ( currentNode == nodeTop ) {
54 XmlNode nextNode = currentNode.NextSibling;
56 if ( nextNode != null ) {
57 currentNode = nextNode;
61 // No next sibling, try the first sibling of from the parent chain
62 nextNode = currentNode;
63 while ( nextNode != nodeTop && nextNode.NextSibling == null )
64 nextNode = nextNode.ParentNode;
66 if ( nextNode == nodeTop ) {
71 currentNode = nextNode.NextSibling;
72 Debug.Assert( currentNode != null );