XmlNode xmlNode = xmlDoc.SelectSingleNode("/bookstore/book[@category='cooking']"); XPathNavigator xpathNav = xmlNode.CreateNavigator(); // Retrieve the title of a book string bookTitle = xpathNav.SelectSingleNode("title").Value;
XmlNodeList xmlNodeList = xmlDoc.SelectNodes("/bookstore/book"); foreach (XmlNode xmlNode in xmlNodeList) { XPathNavigator xpathNav = xmlNode.CreateNavigator(); // Retrieve the author of a book string bookAuthor = xpathNav.SelectSingleNode("author").Value; }In this example, we select multiple XmlNode objects representing book elements in an XML document. We then loop through each XmlNode and create a separate XPathNavigator object for each one using CreateNavigator(). Finally, we retrieve the value of the author element within each book element using an XPath query. Package/library: System.Xml.