所以我可以选择某个节点下的所有结果,但我有以下 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>
如果我想在停止名称是 Cysleys Farm 的情况下选择 stopId(仅通过请求),将如何处理?
我有以下代码:
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;
编辑:
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;
编辑 2
这些项目是否需要进入列表框?因为我需要字符串格式的值才能在 url 上使用。