基于节点值的 LINQ 到 XML 选择,新手问题
给定以下 XML,我想返回 eventtype
id = 23 的所有 eventtitles
。我当前的查询仅查看第一个 eventtype
,所以返回错误的结果。
<event>
<eventtitle>Garrison Keillor</eventtitle>
<eventtypes>
<eventtype id="24"/>
<eventtype id="23"/>
</eventtypes>
</event>
<event>
<eventtitle>Joe Krown Trio featuring Walter Wolfman Washington</eventtitle>
<eventtypes>
<eventtype id="23"/>
</eventtypes>
</event>
LINQ 查询:
Dim query = _
From c In calXML...<event> _
Where c...<eventtypes>.<eventtype>.@id = "23" _
Select c.<eventtitle>.Value, c.<eventlocation>.Value
For Each item In query
Response.Write("<h3>" & item.eventtitle & "</h3>")
Response.Write(item.eventlocation & "<br />")
Next
Given the following XML, I would like to return all eventtitles
where the eventtype
id = 23. My current query only looks at the first eventtype
, so returns the wrong result.
<event>
<eventtitle>Garrison Keillor</eventtitle>
<eventtypes>
<eventtype id="24"/>
<eventtype id="23"/>
</eventtypes>
</event>
<event>
<eventtitle>Joe Krown Trio featuring Walter Wolfman Washington</eventtitle>
<eventtypes>
<eventtype id="23"/>
</eventtypes>
</event>
LINQ query:
Dim query = _
From c In calXML...<event> _
Where c...<eventtypes>.<eventtype>.@id = "23" _
Select c.<eventtitle>.Value, c.<eventlocation>.Value
For Each item In query
Response.Write("<h3>" & item.eventtitle & "</h3>")
Response.Write(item.eventlocation & "<br />")
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要调用
Any
,如下所示:You need to call
Any
, like this: