XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("books.xml"); XPathNavigator nav = xmlDoc.CreateNavigator(); XPathNavigator firstBook = nav.SelectSingleNode("//book"); XPathNavigator subtree = firstBook.ReadSubtree(); subtree.MoveToRoot(); while (subtree.Read()) { Console.WriteLine(subtree.Name + ": " + subtree.Value); }
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("orders.xml"); XPathNavigator nav = xmlDoc.CreateNavigator(); XPathNavigator firstCustomer = nav.SelectSingleNode("//customer"); XPathNavigator subtree = firstCustomer.ReadSubtree(); subtree.MoveToRoot(); while (subtree.Read()) { Console.WriteLine(subtree.Name + ": " + subtree.Value); }The package library used for this example is System.Xml.XPath.