get Bool XML Attribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

get Bool XML Attribute

Demo Code


using System.Xml;
using System.Collections.Generic;
using System.Collections;
using System;//w w w  .ja v a2 s  .  co  m

public class Main{
        public static bool getBoolAttr( XmlElement el, string attrName, bool defaultValue = false ){
         if (el.HasAttribute (attrName) == false) {
            return defaultValue;
         }
         string attrVal = el.GetAttribute (attrName);
         if (attrVal == "1" ||
             attrVal == "true" || attrVal == "True" || attrVal == "TRUE" ||
             attrVal == "yes" || attrVal == "Yes" || attrVal == "YES" ||
            attrVal == "on" || attrVal == "On" || attrVal == "ON"
         ) {
            return true;
         } else {
            return false;
         }
      }
}

Related Tutorials