LINQ to XML返回多个匹配项 [英] LINQ to XML return multiple matches

查看:82
本文介绍了LINQ to XML返回多个匹配项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题是,用户在哪里选择关于城市的属性,然后返回具有任何匹配项的列表城市,从匹配度最高的城市开始.请让我知道使用LINQ to XML是否可以实现,如果可以,我如何实现.

XML示例:

I have a questionare where users where select attributes about cities then I return a list cities that have any of the matches, beginning with the cities with the most matches. Please let me know if this is possible using LINQ to XML and if so, how I can achieve it.

Example of XML:

<cities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<city>
  <name>Atlanta</name>
  <state>GA</state>
  <climate>
    <temp>Hot Weather</temp>
  </climate>
  <region>South</region>
  <recreation>Attending professional sporting events</recreation>
  <healthCare>Seek strong health care facilities and/or major medical univeristy</healthCare>
  <artsCulture>Live near museums, galleries, and cultural events</artsCulture>
  <transportation>Air travel and perfer to live near a major airport</transportation>
  <housing>Seek good rental opportunites</housing>
</city>
<city>
  <name>Indianapolis</name>
  <state>IN</state>
  <climate>
    <temp>Cold weather and snow</temp>
    <seasons>All four seasons</seasons>
  </climate>
  <region>Midwest</region>
  <recreation>Attending professional sporting events</recreation>
  <healthCare>Seek strong health care facilities and/or major medical univeristy</healthCare>
  <artsCulture>Attending the symphony and/or opera</artsCulture>
  <transportation>Air travel and perfer to live near a major airport</transportation>
  <housing>Seek good rental opportunites</housing>
</city>
<city>
  <name>Kansas City</name>
  <state>MO</state>
  <climate>
    <temp>Cold weather and snow</temp>
    <seasons>All four seasons</seasons>
  </climate>
  <region>Midwest</region>
  <recreation>Attending professional sporting events</recreation>
  <healthCare>Seek strong health care facilities and/or major medical univeristy</healthCare>
  <artsCulture>I like attending traveling theatre shows and ballet companies</artsCulture>
  <transportation>Air travel and perfer to live near a major airport</transportation>
  <housing></housing>
</city>
</cities>





然后,在调查表中,用户将选择他们想要的天气,住在主要机场附近,寻找良好的出租物业并喜欢参加专业体育赛事,它将返回城市以及多少个匹配项:

亚特兰大(4/4)
印第安纳波利斯(3/4)
堪萨斯城(2/4)

谢谢!
我们将不胜感激.





Then in the questionnaire, the user would select they want hot weather, live near major airport, seek good rental properties and like to attend professional sporting events, it would return city and how many matches:

Atlanta (4/4)
Indianapolis (3/4)
Kansas City (2/4)

Thanks!
Any and all help is appreciated.

推荐答案

这应该可以帮助您入门

This should get you started

var rec = doc.Descendants("recreation").Where(e => e.Value == "Attending professional sporting events").ToList();
var housing = doc.Descendants("housing").Where(e => e.Value == "Seek good rental opportunites").ToList();




LINQ to XML [




LINQ to XML[^]


这篇关于LINQ to XML返回多个匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆