Get XElement Attribute - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Get XElement Attribute

Demo Code


using System.Xml.Linq;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from   w ww  .j  a v a 2 s  .c o m

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

Related Tutorials