private static int GetDepth(XPathNavigator nav) { int depth = 0; while (nav.MoveToParent()) { depth++; } return depth; }