get XML Int Attribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

get XML Int Attribute

Demo Code


using System.Xml;
using System.Collections.Generic;
using System.Collections;
using System;/*from   w  w  w  .ja  v  a  2  s  .c om*/

public class Main{
        public static int getIntAttr( XmlElement el, string attrName, int defaultValue = 0, int min = System.Int32.MinValue, int max = System.Int32.MaxValue ){
         if (el.HasAttribute (attrName) == false) {
            return defaultValue;
         }
         try {
            int ret = Int32.Parse (el.GetAttribute (attrName));
            if(ret > max){
               ret = max;
            }
            if(ret < min){
               ret = min;
            }
            return ret;
         } catch (Exception e){
            return defaultValue;
         }
      }
}

Related Tutorials