Call GetElementsByTagName to get an element : XmlDocument « XML « C# / C Sharp






Call GetElementsByTagName to get an element

   

using System;
using System.Xml;

public class MainClass {
    private static void Main() {
        XmlDocument doc = new XmlDocument();
        doc.Load("ProductCatalog.xml");

        XmlNodeList prices = doc.GetElementsByTagName("productPrice");

        decimal totalPrice = 0;
        foreach (XmlNode price in prices) {
            totalPrice += Decimal.Parse(price.ChildNodes[0].Value);
        }

        Console.WriteLine("Total catalog value: " + totalPrice.ToString());
    }

}

   
    
  








Related examples in the same category

1.A Simple XML Example
2.LoadXml
3.Save, AppendChild, CreateXmlDeclaration, CreateElement
4.Use Load method in XmlDocument to load xml document
5.Use SelectNodes to query nodes by XPath
6.Get XML Nodes in a Specific XML Namespace
7.Find Elements with an XPath Search
8.Add XmlElement
9.Load With Includes
10.Non CData Normalize