Random thoughts of wisdom - the personal blog of Michael Holm Andersen

Using LINQPad to test your LINQ to XML queries

If you’re a LINQPad user you’re probably used to query your DBML (LINQ to SQL), but did you know that you can also use it for LINQ to Objects, LINQ to XML etc.

A simple example of how to do a query against a XML file (make sure language is set to C# Statements):

var xml = XElement.Load (@"c:\\inetpub\\GWportal\\src\\wwwBackend\\App_Data\\axCache\\

var query =
  from e in xml.Descendants("unittransaction").Descendants()
    where (e.Attribute("name").Value == "ItemRelation" && e.Value.Equals("10020"))
  select e.Parent;

Which gives this result:linqtoxml