Select Single XML Attribute Int - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Select Single XML Attribute Int

Demo Code


using System.Xml;
using System;/*w ww. j a  va 2  s .  c  o  m*/

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

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

        return defaultValue;
    }
}

Related Tutorials