I want to get the Category based total of the following
<?xml version="1.0" encoding="utf-8" ?> - <Data> - <Products> <Product ProductId="1001" ProductName="p1" category="A1" ProductPrice="123.45" /> <Product ProductId="1002" ProductName="p2" category="B1" ProductPrice="100.45" /> <Product ProductId="1003" ProductName="p3" category="A1" ProductPrice="223.45" /> <Product ProductId="1004" ProductName="p4" category="B1" ProductPrice="200.45" /> </Products> .... What is the modification needed to achieve it in the following ?(nothing is returned in my query)
XDocument doc = XDocument.Load("Product.xml"); var sum = from p in doc.Descendants("Product") group p by p.Attribute("Category") into g select new { category = g.Key, total = g.Sum(p =>(double)p.Attribute("ProductPrice")) };