XmlDocument doc = new XmlDocument(); doc.Load("books.xml"); XmlNodeList books = doc.DocumentElement.SelectNodes("//book[@category='fiction']");
string xml = "In both examples, the ElementsByXPath method is used to retrieve specific elements from an XmlDocument object based on a given XPath query. This method can be useful when working with complex XML documents where it may be difficult or tedious to manually parse through the document to find specific elements."; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeList names = doc.DocumentElement.SelectNodes("//person[@gender='male']/name"); John Jane