tags:

views:

35

answers:

1

How to group xml element values

XDocument.Descandants("Customer").GroupBy(c=>c.Element("ServiceId"));

This is not working.

Is there any way to group this?

+2  A: 

Assuming that ServiceId is a child element of Customer at your Xml, you can group your customers by ServiceId's value by :

XDocument.Descandants("Customer")
     .GroupBy(c=>c.Element("ServiceId").Value);

If ServiceId is an attribute of Customer element, try this :

XDocument.Descandants("Customer")
     .GroupBy(c=>c.Attribute("ServiceId").Value);
Canavar