Get XML Elements By Tag Name : Tag « XML « C# / C Sharp






Get XML Elements By Tag Name

Get XML Elements By Tag Name

using System;
using System.Xml;

public class FindNodesByName {

    private static void Main() {

        // Load the document.
        XmlDocument doc = new XmlDocument();
        doc.Load("books.xml");

        // Retrieve all prices.
        XmlNodeList nodeList = doc.GetElementsByTagName("B");

        foreach (XmlNode node in nodeList) {
            Console.WriteLine(node.ChildNodes[0].Value);
        }
    }
}

// books.xml
/*
<books>
  <A property="a">
    <B>text</B>
    <C>textg</C>
    <D>99999</D>
  </A>
</books>
*/
           
       








Related examples in the same category