Showing posts with label Querying the XML file using LINQ. Show all posts
Showing posts with label Querying the XML file using LINQ. Show all posts

Saturday, March 13, 2010

Querying the XML file using LINQ

In this example i tried to find the available balance by passing the account number as parameter to the function through Linq



XDocument doc = XDocument.Load("C:\\Account.xml");
var result = from ds in doc.Descendants("Account")
where ds.Element("IDNumber").Value == account.ToString()
select new
{
Balance = ds.Element("AvailableBalance").Value,
AccountID = ds.Element("IDNumber").Value

};
return result.ToArray();


My accounts XML will be



2554
50045


2555
4645