So i am able to select all the results under a certain node, but I have the following XML
<ArrayOfStop>
<Stop>
<StopName>Rajdutt Restaurant</StopName>
<route_stop />
<route_stop_stop />
<route_stop_timetable_stop />
<stopId>6400</stopId>
</Stop>
<Stop>
<StopName>Cysleys Farm (by request only)</StopName>
<route_stop />
<route_stop_stop />
<route_stop_timetable_stop />
<stopId>6401</stopId>
</Stop>
<ArrayOfStop>
If i want to select stopId if the stopname was Cysleys Farm (by request only) how would one go about it?
I have the following code:
XDocument loadedData = XDocument.Load("People.xml");
var data = from query in loadedData.Descendants("ArrayOfStop")
select new Person
{
StopName = (string)query.Element("StopName")
};
listBox.ItemsSource = data;
EDIT:
var data = from query in loadedData.Descendants("ArrayOfStop")
where query.Element("StopName").Value == "Cysleys Farm (by request only)"
select query.Element("StopId").Value;
select new Person
{
FirstName = (string)query.Element("StopName"),
//LastName = (string)query.Element("Long"),
//Age = (int)query.Element("age")
};
listBox.ItemsSource = data;

EDIT 2
Do the items need to be going into a list box? As i need the value in a string format to use on a url.
1 Answer