XPathNavigator.MoveToFirstAttribute moves XPathNavigator to the first attribute of the current node.
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml.XPath;
public class MainClass
{
public static void Main()
{
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();
XPathNodeIterator nodes = navigator.SelectDescendants("book", "", false);
while (nodes.MoveNext())
{
XPathNavigator navigator2 = nodes.Current.Clone();
navigator2.MoveToFirstAttribute();
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);
while (navigator2.MoveToNextAttribute())
{
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);
}
}
}
}
Related examples in the same category