internal bool MoveToPrevious(string localName, string namespaceURI) { XPathNavigator navClone = Clone(); localName = (localName != null) ? NameTable.Get(localName) : null; while (MoveToPrevious()) { if (NodeType == XPathNodeType.Element && (object)localName == (object)LocalName && namespaceURI == NamespaceURI) return true; } MoveTo(navClone); return false; }
public static string GetXPath (XPathNavigator n) { switch (n.NodeType) { case XPathNodeType.Root: return "/"; case XPathNodeType.Attribute: { string ret = "@" + n.Name; n.MoveToParent (); string s = GetXPath (n); return s + (s == "/" ? "" : "/") + ret; } case XPathNodeType.Element: { string ret = n.Name; int i = 1; while (n.MoveToPrevious ()) { if (n.NodeType == XPathNodeType.Element && n.Name == ret) i++; } ret += "[" + i + "]"; if (n.MoveToParent ()) { string s = GetXPath (n); return s + (s == "/" ? "" : "/") + ret; } } break; } throw new Exception ("node type not supported for editing"); }