Load an XML and query using LINQ

Posted by Karthikanbarasan under LINQ category on | Points: 40 | Views : 1599
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.Write("Press Enter to continue:");


Comments or Responses

Login to post response