LINQ To XML Program

Gopesh9
Posted by Gopesh9 under LINQ category on | Points: 40 | Views : 1211
A Simple LINQ to XML Program That Parses a Small XML File and Finds Customers Who Live in Mexico D.F.

using System;
using System.Linq;
using System.Xml.Linq;

namespace SimpleXmlExample
{
class Program
{
public static void main(string[] args)
{
XDocument customers = new XDocument("Customers.xml");
var query = from e in customers.Descendants("Customer") where e.Attribute("City").Value == "Mexico D.F." select e;
foreach (var customer in query)
{
Console.WriteLine(customer);
}
}
}
}

Comments or Responses

Login to post response