Safe Parse Xml Attribute Bool - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Safe Parse Xml Attribute Bool

Demo Code


using System.Xml;
using System.Text;
using System.Collections.Generic;
using System;//w w  w  .j  a va 2 s . co m

public class Main{
        public static bool SafeParseXmlAttribute_Bool(XmlNode xNode, string attributeName, bool defaultValue)
    {
        var attr = xNode.Attributes[attributeName];
        if ((attr == null) || (string.IsNullOrWhiteSpace(attr.Value)))
        {
            return defaultValue;
        }

        return System.Convert.ToBoolean(attr.Value);
    }
}

Related Tutorials