Mega Code Archive

 
Categories / C# Tutorial / XML LINQ
 

Query XML

using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using System.Text;     class Program     {         static void Main(string[] args)         {             string xmlFileName = "e.xml";             XDocument customers = XDocument.Load(xmlFileName);             var queryResults =                 from c in customers.Descendants("order").Attributes("orderYear")                 select c;             foreach (var item in queryResults)             {                 Console.WriteLine(item);             }                         }     }