Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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>




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.
Posted
Updated 24-Feb-10 5:36am
v3

1 solution

This should get you started

C#
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900