internal bool MoveToNonDescendant()
{
// If current node is document, there is no next non-descendant
if (NodeType == XPathNodeType.Root)
return false;
// If sibling exists, it is the next non-descendant
if (MoveToNext())
return true;
// The current node is either an attribute, namespace, or last child node
XPathNavigator navSave = Clone();
if (!MoveToParent())
return false;
switch (navSave.NodeType)
{
case XPathNodeType.Attribute:
case XPathNodeType.Namespace:
// Next node in document order is first content-child of parent
if (MoveToFirstChild())
return true;
break;
}
while (!MoveToNext())
{
if (!MoveToParent())
{
// Restore original position and return false
MoveTo(navSave);
return false;
}
}
return true;
}