Get Bool Value from XmlNode - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get Bool Value from XmlNode

Demo Code


using System.Xml;
using System.IO;//from ww  w  . ja v a  2  s .  c om
using System;

public class Main{
        //-------------------------------------------------------------------------------------------------//

        public static bool GetBoolValue(XmlNode xmlNode, string strXmlNode, bool allowEmpty)
        {
            //
            // Get node's string value
            //
            string value = GetXmlValue(xmlNode, strXmlNode, allowEmpty);

            //
            // Convert to a boolean
            //
            bool boolValue = false;
            try
            {
                boolValue = Boolean.Parse(value);
            }
            catch
            {
                throw new ArgumentException(strXmlNode, STRERR_XmlInvalidBoolean);
            }

            return boolValue;
        }
}

Related Tutorials