Get Decimal from XmlNode - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get Decimal from XmlNode

Demo Code


using System.Globalization;
using System.Security.Cryptography;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Collections;
using System.Xml.XPath;
using System.Text;
using System.Xml;
using System.IO;//from w  w w.  j  a v  a  2  s  . c om
using System;

public class Main{
        /// <summary>
      /// 
      /// </summary>
      /// <param name="Node"></param>
      /// <param name="NodeName"></param>
      /// <returns></returns>
      public static decimal GetDecimal(XmlNode Node, string NodeName)
      {
         decimal result = -1.0m;
         string s = GetString(Node, NodeName).Trim();
         if (s.Length > 0)
         {
            try
            {
               result = Decimal.Parse(s, CultureInfo.InvariantCulture);
            }
            catch (ArgumentNullException)
            {
            }
            catch (FormatException)
            {
            }
            catch (OverflowException)
            {
            }
         }
         return result;
      }
        /// <summary>
      /// 
      /// </summary>
      /// <param name="Navigator"></param>
      /// <param name="XPath"></param>
      /// <returns></returns>
      public static decimal GetDecimal(XPathNavigator Navigator, XPathExpression XPath)
      {
         decimal result = -1.0m;
         string s = GetString(Navigator, XPath).Trim();
         if (s.Length > 0)
         {
            try
            {
               result = Decimal.Parse(s, CultureInfo.InvariantCulture);
            }
            catch (ArgumentNullException)
            {
            }
            catch (FormatException)
            {
            }
            catch (OverflowException)
            {
            }
         }
         return result;
      }
        /// <summary>
      /// 
      /// </summary>
      /// <param name="Navigator"></param>
      /// <param name="NodeName"></param>
      /// <returns></returns>
      public static decimal GetDecimal(XPathNavigator Navigator, string NodeName)
      {
         decimal result = -1.0m;
         string s = GetString(Navigator, NodeName).Trim();
         if (s.Length > 0)
         {
            try
            {
               result = Decimal.Parse(s, CultureInfo.InvariantCulture);
            }
            catch (ArgumentNullException)
            {
            }
            catch (FormatException)
            {
            }
            catch (OverflowException)
            {
            }
         }
         return result;
      }
}

Related Tutorials