Use Linq to read xml file and query attribute value : XAttribute « XML LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Xml.Linq;

public class MainClass
{
    public static void Main()
    {
        XElement root = null;
        root = XElement.Load(@"\employees.xml");
        var result = from item in root.Elements("employee")
                     where item.Attributes("employeeid").Count() > 0
                     select item.Attribute("employeeid").Value;
        foreach (var obj in result)
        {
            Console.WriteLine(obj);
        }

    
    }
}








31.3.XAttribute
31.3.1.Linq To Xml Constructors
31.3.2.Use Linq to read xml file and query attribute value
31.3.3.Displays all the attributes from an Xml tag