views:

32

answers:

1

I'm trying to get all the email nodes for the customers in the sample xml and binding it to a grid. I can't seemt to get past the linq query!

Sample XML:

<group>
<customer>
<email>[email protected]></email>
</customer>
<customer>
<email>[email protected]</email>
</customer>
</group>

var query = from result in xml.Elements("customer")
select new
{
email = xml.Element("email").Value
};

gridview1.DataSource = query;
gridview1.DataBind();
+1  A: 

Elements() will only get you direct children, therefore, if your xml variable is an XDocument, its only direct children (according to the little sample) are group elements.

Try:

var query = from result in xml.Descendants("customer")
select new { email = result.Element("email").Value };
SirDemon