string xml = ""; XPathDocument doc = new XPathDocument(new StringReader(xml));
string xml = "This example navigates an XML document using an XPath expression to select all book elements. It then uses an XPathNodeIterator to iterate over each selected element and retrieve its attributes. Package library: This class is part of the System.Xml.XPath.Interfaces assembly in the .NET Framework."; XPathDocument doc = new XPathDocument(new StringReader(xml)); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator books = nav.Select("//book"); while (books.MoveNext()) { Console.WriteLine("Title: " + books.Current.GetAttribute("title", "")); Console.WriteLine("Author: " + books.Current.GetAttribute("author", "")); Console.WriteLine("Genre: " + books.Current.GetAttribute("genre", "")); Console.WriteLine(); }