public override bool Read() {
this.attrCount = -1;
switch (this.state) {
case State.Error:
case State.Closed:
case State.EOF:
return false;
case State.Initial:
// Starting state depends on the navigator's item type
this.nav = this.navToRead;
this.state = State.Content;
if ( XPathNodeType.Root == this.nav.NodeType ) {
if( !nav.MoveToFirstChild() ) {
SetEOF();
return false;
}
this.readEntireDocument = true;
}
else if ( XPathNodeType.Attribute == this.nav.NodeType ) {
this.state = State.Attribute;
}
this.nodeType = ToXmlNodeType( this.nav.NodeType );
break;
case State.Content:
if ( this.nav.MoveToFirstChild() ) {
this.nodeType = ToXmlNodeType( this.nav.NodeType );
this.depth++;
this.state = State.Content;
}
else if ( this.nodeType == XmlNodeType.Element
&& !this.nav.IsEmptyElement ) {
this.nodeType = XmlNodeType.EndElement;
this.state = State.EndElement;
}
else
goto case State.EndElement;
break;
case State.EndElement:
if ( 0 == depth && !this.readEntireDocument ) {
SetEOF();
return false;
}
else if ( this.nav.MoveToNext() ) {
this.nodeType = ToXmlNodeType( this.nav.NodeType );
this.state = State.Content;
}
else if ( depth > 0 && this.nav.MoveToParent() ) {
Debug.Assert( this.nav.NodeType == XPathNodeType.Element, this.nav.NodeType.ToString() + " == XPathNodeType.Element" );
this.nodeType = XmlNodeType.EndElement;
this.state = State.EndElement;
depth--;
}
else {
SetEOF();
return false;
}
break;
case State.Attribute:
case State.AttrVal:
if ( !this.nav.MoveToParent() ) {
SetEOF();
return false;
}
this.nodeType = ToXmlNodeType( this.nav.NodeType );
this.depth--;
if (state == State.AttrVal)
this.depth--;
goto case State.Content;
case State.InReadBinary:
state = savedState;
readBinaryHelper.Finish();
return Read();
}
return true;
}