Gets the sum of the double values for all nodes returned by executing the supplied XPath query on the supplied Node - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Gets the sum of the double values for all nodes returned by executing the supplied XPath query on the supplied Node

Demo Code


using System.Xml.Xsl;
using System.Xml;
using System.Text.RegularExpressions;
using System.Text;
using System;/*from   w  ww  . j  a v  a  2 s.  c o  m*/

public class Main{
        #endregion

      #region GetNodeSum(); GetNodeText();
      /// <summary>
      /// Gets the sum of the double values for all nodes returned by executing the supplied XPath query on the supplied Node
      /// </summary>
      /// <param name="XPath">The string XPath to the nodes containing numeric values to be added</param>
      /// <param name="Node">The XmlNode to be selected from</param>
      /// <returns>The double value containing the sum of all double values in the nodes returned by the XPath query</returns>
      public static double GetNodeSum(string XPath, XmlNode Node)
      {
         double dOutput = 0;
         foreach(XmlNode oChildNode in Node.SelectNodes(XPath))
         {
            dOutput += Parser.ToDouble(oChildNode.InnerText);
         }
         return dOutput;
      }
}

Related Tutorials