Load an XML and query using LINQ

Karthikanbarasan
Posted by Karthikanbarasan under LINQ category on | Points: 40 | Views : 1617
This code sample shows how to load an XML and use LINQ to query and display the result


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

namespace Demo
{
class Program
{
static void Main(string[] args)
{
string xmlFileName = @"C:\CustomerOrders.xml";
XDocument cust = XDocument.Load(xmlFileName);

Console.WriteLine("Elements in XML:");
var qResult = from c in cust.Elements()
select c.Name;
foreach (var itemList in qResult)
{
Console.WriteLine(itemList);
}
Console.Write("Press Enter to continue:");
Console.ReadLine();

}
}
}

Comments or Responses

Login to post response