Get XML Elements By Tag Name

image_pdfimage_print


   


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>
*/
           
          


This entry was posted in XML-RPC. Bookmark the permalink.