using System.Text;
using System.Xml.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
class LinqToXml
{
static void Main()
{
XDocument doc = XDocument.Load("data.xml");
var filtered = from p in doc.Descendants("Product")
join s in doc.Descendants("Supplier")
on (int)p.Attribute("SupplierID")
equals (int)s.Attribute("SupplierID")
where (decimal)p.Attribute("Price") > 10
orderby (string)s.Attribute("Name"),
(string)p.Attribute("Name")
select new
{
SupplierName = (string)s.Attribute("Name"),
ProductName = (string)p.Attribute("Name")
};
foreach (var v in filtered)
{
Console.WriteLine("Supplier={0}; Product={1}",
v.SupplierName, v.ProductName);
}
}
}
//File: data.xml
/*
<?xml version="1.0"?>
<Data>
<Products>
<Product Name="E" Price="9.99" SupplierID="1" />
<Product Name="A" Price="14.99" SupplierID="2" />
<Product Name="C" Price="13.99" SupplierID="1" />
<Product Name="D" Price="10.99" SupplierID="3" />
</Products>
</Data>
*/