Get XML Attribute from XmlNode - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get XML Attribute from XmlNode

Demo Code


using System.Xml;
using System;/*from  ww w.  j  a  v  a2s . c o m*/

public class Main{
        public static String GetAttribute(this XmlNode xmlNode, String attrName)
        {
            foreach (XmlNode node in xmlNode.ChildNodes)
            {
                if (String.Compare(node.Name, attrName, true) == 0)
                {
                    return node.InnerText;
                }      
            }

            return null;
        }
}

Related Tutorials