public MoveToChild ( XPathNodeType type ) : bool | ||
type | XPathNodeType | |
return | bool |
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(""); XPathNavigator nav = xmlDoc.CreateNavigator(); nav.MoveToFirstChild(); Console.WriteLine("Node Type: " + nav.NodeType); Console.WriteLine("Node Name: " + nav.Name); Harry Potter
Node Type: Element Node Name: book
XDocument xDoc = XDocument.Load("books.xml"); XPathNavigator nav = xDoc.CreateNavigator(); while (nav.MoveToChild("book", "")) { Console.WriteLine(nav.SelectSingleNode("title").Value); Console.WriteLine(nav.SelectSingleNode("author").Value); nav.MoveToParent(); }
Harry Potter J.K. Rowling The Lord of the Rings J.R.R. Tolkien
using System.Xml.XPath;The necessary library package is included in the .NET framework.