Mega Code Archive

 
Categories / C# / XML
 

Get boolean value if an attribute is 1 or true

//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 GetBoolAttrib(XmlNode node, string attrib, bool defVal)     public static bool GetBoolAttrib(XmlNode node, string attrib, bool defVal)     {       XmlAttribute xmlAttrib = node.Attributes[attrib];       if (xmlAttrib == null)         return defVal;       string val = xmlAttrib.Value;       if (val == null || val == string.Empty)         return defVal;       bool returnVal = (val == "1" || val.ToLower() == "true");       return returnVal;     }     #endregion   } }