Get the XPath to an XElement?

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2009-01-16T20:50:48Z Indexed on 2010/03/22 14:41 UTC
Read the original article Hit count: 360

Filed under:
|
|
|

I've got an XElement deep within a document. Given the XElement (and XDocument?), is there an extension method to get its full (i.e. absolute, e.g. /root/item/element/child) XPath?

E.g. myXElement.GetXPath()?

EDIT: Okay, looks like I overlooked something very important. Whoops! The index of the element needs to be taken into account. See my last answer for the proposed corrected solution.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xpath