I'm new to XML, so please bear with me.
I'm using XPathNavigator and XPathNodeIterator to return a set of xml nodes
from a document that looks like this:
<root>
<book title="Some Title">
<chapter>
<title>Chapter 1</title>
<starting_page>34</starting_page>
<number_of_pages>15</number_of_pages>
</chapter>
<chapter>
<title>Chapter 2</title>
<starting_page>50</starting_page>
<number_of_pages>15</number_of_pages>
</chapter>
</book>
</root>
My code:
XPathDocument xmlDoc = new XPathDocument("books.xml");
XPathNavigator xmlNav = xmlDoc.CreateNavigator();
XPathExpression xmlExpr = xmlNav.Compile("root/book[@title='Some
Title']/chapter");
XPathNodeIterator xmlItor = xmlNav.Select(xmlExpr);
xmlItor.MoveNext();
At this point I have a collection of chapter nodes in my xmlItor, but how do
I then get the data out of the title, starting_page, and number_of_pages
elements? I would prefer to be able to refer to them by element name.