public abstract MoveToFirstAttribute ( ) : bool | ||
return | bool |
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load("example.xml"); XPathNavigator navigator = xmlDocument.CreateNavigator(); navigator.MoveToFirstChild(); if (navigator.MoveToFirstAttribute()) { Console.WriteLine(navigator.Name + ": " + navigator.Value); }
using System.Xml.Linq; XDocument xDocument = XDocument.Load("example.xml"); XPathNavigator navigator = xDocument.CreateNavigator(); navigator.MoveToFirstChild(); if (navigator.MoveToFirstAttribute()) { Console.WriteLine(navigator.Name + ": " + navigator.Value); }In this example, an XML document is loaded into an XDocument object instead of an XmlDocument object. The navigator is created from the XDocument object, and the same navigation logic is used as the previous example. This code example uses System.Xml.XPath library.