Get XML Attribute Value - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get XML Attribute Value

Demo Code


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

public class Main{
        public static string GetAttributeValue(this XmlElement @this, string attributeName)
        {
            var result = @this.Attributes
                              .Cast<XmlAttribute>()
                              .FirstOrDefault(x => x.Name.Equals(attributeName, StringComparison.OrdinalIgnoreCase));

            return result == null ? null : result.Value;
        }
}

Related Tutorials