Get XML Bool Attribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get XML Bool Attribute

Demo Code


using System.Xml;

public class Main{
        public static bool GetBoolAttribute(this XmlNode node, string key, bool defaultValue)
        {//from www .  jav  a 2  s.c om
            XmlAttributeCollection attributes = node.Attributes;
            bool val = defaultValue;

            if (attributes[key] != null
                && !string.IsNullOrEmpty(attributes[key].Value))
            {
                bool.TryParse(attributes[key].Value, out val);
            }
            return val;
        }
}

Related Tutorials