private void button1_Click(object sender, EventArgs e)
// read all book elements
XmlDocument doc = new XmlDocument();
XmlNodeList bookdetails = doc.GetElementsByTagName("bookdetails");
// For each book oget a name and print it; any other book elements can be accessed here
foreach (XmlNode book in bookdetails)
XmlNode nameNode = book.SelectSingleNode("./name"); // we suggest only one name element exists for a book
System.Diagnostics.Debug.WriteLine("Name = " + nameNode.InnerText); // see output window
Open in new window
I believe it is better to get book nodes ("bookdetails") and check any children like "name" elements, because books may have other elements like "author", ISBN", "publisher" etc.
XmlNodeList names = doc1.SelectNodes("//bookdetails/name");
IT issues often require a personalized solution. With Ask the Experts™, submit your questions to our certified professionals and receive unlimited, customized solutions that work for you.
Take hold of your future.