<?xml version="1.0"?>
-<bookstore>
<book >
<title>aaaa</title>
-<author >
<first-name>firts</first-name>
<last-name>last</last-name>
</author>
<price>8.23</price>
<otherbooks>
<book >
<title>bbb</title>
<price>18.23</price>
</book>
<book >
<title>ccc</title>
<price>11.22</price>
</book>
</otherbooks>
</book>
</bookstore>
I would like to select all books at different levels and then display information about each one (author, title and price). At the moment code would also display otherbooks for first book. What would be the best way of displaying only required information. I need to use XPath.
xPathDoc = new XPathDocument(filePath);
xPathNavigator = xPathDoc.CreateNavigator();
XPathNodeIterator xPathIterator = xPathNavigator.Select("/bookstore//book");
foreach (XPathNavigator navigator in xPathIterator)
{
XPathNavigator clone = navigator.Clone();
clone.MoveToFirstChild();
Console.WriteLine(clone.Name + " : " + clone.Value);
while (clone.MoveToNext())
{
Console.Write(clone.Name + " : " + clone.Value + " | ");
}
}
<book />elements at all levels below<bookstore />. Don't you wantbook/otherbooks/bookto be selected? - hielsnoppe