Get XML Node By Name Attribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get XML Node By Name Attribute

Demo Code


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

public class Main{
        public static XElement GetNodeByNameAttribute(XElement item, string NodeName, string AttrName, string AttrValue)
        {
            var res = (from e in item.Elements(NodeName)
                       where e.Attribute(AttrName).Value == AttrValue
                       select e).SingleOrDefault();
            return res;
        }
}

Related Tutorials