Hi All
how can I query an xml file where I have multiple items with the same name, so that I can get all items back. Currently I only get the first result back. I managed to get it to work with the following code, but this returns all items where the specific search criteria is met. What I want as output is to get two results back where the location is Dublin for example. The question is how can I achieve this with linq to xml
Cheers Chris,
Here is the code
string location = "Oslo";
var training = (from item in doc.Descendants("item")
where item.Value.Contains(location)
select new
{
event = item.Element("event").Value,
event_location = item.Element("location").Value
}).ToList();
The xml file looks like this
<training>
<item>
<event>C# Training</event>
<location>Prague</location>
<location>Oslo</location>
<location>Amsterdam</location>
<location>Athens</location>
<location>Dublin</location>
<location>Helsinki</location>
</item>
<item>
<event>LINQ Training</event>
<location>Bucharest</location>
<location>Oslo</location>
<location>Amsterdam</location>
<location>Helsinki</location>
<location>Brussels</location>
<location>Dublin</location>
</item>
</training>