Select Single XML Attribute Decimal - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Select Single XML Attribute Decimal

Demo Code


using System.Xml;
using System;/*  ww  w  . j a v a  2  s .co m*/

public class Main{
        public static decimal? SelectSingleAttributeDecimal(XmlNode node, string name, decimal? defaultValue = null)
    {
        if (node?.Attributes == null)
        {
            return defaultValue;
        }

        workAttr = node.Attributes[name];
        if (workAttr != null && decimal.TryParse(workAttr.Value, out dTryParse))
        {
            return dTryParse;
        }

        return defaultValue;
    }
}

Related Tutorials