Get XML Attribute from XElement - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Get XML Attribute from XElement

Demo Code


using System.Xml.Linq;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//www .j  ava2  s.com

public class Main{
        public static string GetAttribute(XElement _this, string name)
        {
            if (_this != null)
                return _this.Attribute(name) != null
                    ? _this.Attribute(name).Value
                    : GetAttribute(_this.Parent, name);
            else
                return null;
        }
}

Related Tutorials