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");
}