You need to get a collection of "book" nodes first, then you can use your "foreach" loop.
XmlDocument doc = new XmlDocument();
doc.Load("inventory.xml");
XmlNodeList books = doc.SelectNodes("//book");
foreach (XmlNode book in books)
{
XmlNodeList authors = book.SelectNodes("//author");
foreach (XmlNode author in authors)
{
BookListView.Items.Add(new ListViewItem(author.InnerText));
}
}
Note: I based this code on this
MS XML example file[
^]. I think that the xpath code I used is generic enough to also work on your xml file, but you may need to modify the "SelectNodes" statements.
A good quick reference is:
XPath Examples[
^]