private bool ReadNextNode( bool fSkipChildren ) {
if ( readState != ReadState.Interactive && readState != ReadState.Initial ) {
nodeType = XmlNodeType.None;
return false;
}
bool bDrillDown = !fSkipChildren;
XmlNodeType nt = readerNav.NodeType;
//only goes down when nav.NodeType is of element or of document at the initial state, other nav.NodeType will not be parsed down
//if nav.NodeType is of EntityReference, ResolveEntity() could be called to get the content parsed;
bDrillDown = bDrillDown
&& ( nodeType != XmlNodeType.EndElement )
&& ( nodeType != XmlNodeType.EndEntity )
&& ( nt == XmlNodeType.Element || ( nt == XmlNodeType.EntityReference && bResolveEntity ) ||
( ( ( readerNav.NodeType == XmlNodeType.Document ) || ( readerNav.NodeType == XmlNodeType.DocumentFragment ) ) && readState == ReadState.Initial) );
//first see if there are children of current node, so to move down
if ( bDrillDown ) {
if ( readerNav.MoveToFirstChild() ) {
nodeType = readerNav.NodeType;
curDepth++;
if ( bResolveEntity )
bResolveEntity = false;
return true;
} else if ( readerNav.NodeType == XmlNodeType.Element
&& !readerNav.IsEmptyElement ) {
nodeType = XmlNodeType.EndElement;
return true;
}
//entity reference node shall always have at least one child ( at least a text node with empty string )
Debug.Assert( readerNav.NodeType != XmlNodeType.EntityReference );
// if fails to move to it 1st Child, try to move to next below
return ReadForward( fSkipChildren );
} else {
if ( readerNav.NodeType == XmlNodeType.EntityReference && bResolveEntity ) {
//The only way to get to here is because Skip() is called directly after ResolveEntity()
// in this case, user wants to skip the first Child of EntityRef node and fSkipChildren is true
// We want to pointing to the first child node.
readerNav.MoveToFirstChild(); //it has to succeeded
nodeType = readerNav.NodeType;
curDepth++;
bResolveEntity = false;
return true;
}
}
return ReadForward( fSkipChildren ); //has to get the next node by moving forward
}