I have an API that returns data in XML. The relevant part of the XML looks like this:
<data name="Rows">
<data Name="Row">
<data name="CONTACT">John Smith</data>
<data name="PHONE1">(555)123-4567</data>
</data>
<data Name="Row">
<data name="CONTACT">Jim Smith</data>
<data name="PHONE1">(555)123-6754</data>
</data>
</data>
I can get a collection of nodes of each Row with this:
var query = from item in xdoc.Root.Descendants("data")
where (string)item.Attribute("Name") == "Row"
select item;
And a collection of strings for each element if I filter by attribute:
var query2 = from item in query.Elements("data")
where (string)item.Attribute("name") == "CONTACT"
select item;
returns: John Smith, James Smith
But I can't figure out how to get each contact name and phone number together.
Something like:
foreach(var row in query)
{
contact = query.???;
phone1 = query.????;
}