Get Int Attribute from XML - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get Int Attribute from XML

Demo Code


using System.Xml;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/* www  .  ja  v a2s. co  m*/

public class Main{
        public static int GetIntAttr(this XmlElement element, string attrName)
        {
            try
            {
                return int.Parse(element.GetAttr(attrName));
            }
            catch (Exception)
            {
                return 0;
            }
        }
        public static string GetAttr(this XmlElement element, string attrName)
        {
            XmlAttribute attr = element.Attributes[attrName];
            return (attr != null) ? attr.Value : string.Empty;
        }
}

Related Tutorials