Get attribute value and convert to integer type

   
 

//Microsoft Public License (Ms-PL)
//http://dbmlmanager.codeplex.com/license
#region using
using System;
using System.Xml;
#endregion

namespace DbmlManager.Lib.Utility
{
  #region Class Docs
  /// <summary>
  /// Summary description for XmlUtil.
  /// </summary>
  #endregion

  public class XmlUtil
  {

    #region GetIntAttrib(XmlNode node, string attrib, int defVal)
    public static int GetIntAttrib(XmlNode node, string attrib, int defVal)
    {
      XmlAttribute xmlAttrib = node.Attributes[attrib];
      if (xmlAttrib == null)
        return defVal;

      string val = xmlAttrib.Value;
      if (val == null || val == string.Empty)
        return defVal;

      int returnVal = defVal;
      int.TryParse(val, out returnVal);

      return returnVal;
    }
    #endregion
  }
}

   
     



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