Could someone supply some code that would get the xpath of a System.Xml.XmlNode instance?
Thanks!
I had to do this recently. Only elements needed to be considered. This is what I came up with:
private string GetPath(XmlElement el)
{
List pathList = new List();
XmlNode node = el;
while (node is XmlElement)
{
pathList.Add(node.Name);
node = node.ParentNode;
}
pathList.Reverse();
string[] nodeNames = pathList.ToArray();
return String.Join("/", nodeNames);
}