| XPathDocument, XPathNavigator, XPathNodeIterator sample with C# |
| Section: XML Webservices | Rating: Not rated yet! |
 | CodeGod submitted this resource The member's homepage is http://www.codegod.de Visit the profile here |
<?xml version="1.0" encoding="utf-8" ?>
<books>
<book auhtor="Ernest Hemmingway">Fiesta</book>
<book author="Unknown">The principles of software development</book>
</books>
private static void NavigateBooks()
{
XPathDocument docBooks = new XPathDocument("../../Books.xml");
XPathNavigator navBooks = docBooks.CreateNavigator();
XPathNodeIterator iterBooks = navBooks.Select("books/book");
foreach (XPathNavigator nodeBook in iterBooks)
{
Console.WriteLine("Found book: {0}", nodeBook.Value);
Console.WriteLine("Author: {0}", nodeBook.GetAttribute("author", String.Empty));
}
}