XElement element = XElement.Parse(""); string xpath = element.Element("book").Element("title").GetXPath(); Console.WriteLine(xpath); // output: "bookstore/book/title" The Great Gatsby
XDocument document = XDocument.Load("books.xml"); IEnumerableIn this example, we load an XML document from a file called "books.xml" and then use the Descendants method to select all elements with the name "price". We iterate over each element and call GetXPath to print the XPath expression to the console. Package Library: System.Xml.Linq (part of the .NET Framework)elements = document.Descendants("price"); foreach (XElement element in elements) { string xpath = element.GetXPath(); Console.WriteLine(xpath); }