Get Integer from XmlNode - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get Integer 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;//  w  ww .ja  v a2  s.  com
using System;

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

Related Tutorials