private XmlNode PrevElemInPreOrder( XmlNode curNode ) {
Debug.Assert( curNode != null );
//For preorder walking, the previous node will be the right-most node in the tree of PreviousSibling of the curNode
XmlNode retNode = curNode.PreviousSibling;
// so if the PreviousSibling is not null, going through the tree down to find the right-most node
while ( retNode != null ) {
if ( retNode.LastChild == null )
break;
retNode = retNode.LastChild;
}
// if no PreviousSibling, the previous node will be the curNode's parentNode
if ( retNode == null )
retNode = curNode.ParentNode;
if ( retNode == this.rootNode )
retNode = null;
return retNode;
}