I got a XML document with a lot of data divided into category->subcategory. Like this:
<?xml version="1.0" encoding="utf-8" ?>
<data>
<car>
<transmission>
<option value="1" text="Manual" />
<option value="2" text="Automatic" />
</transmission>
<milage>
<option value="2" text="0-499" />
<option value="4" text="500-999" />
<option value="6" text="1000-1499" />
<option value="8" text="1500-1999" />
<option value="10" text="2000-2499" />
</milage>
<fuel>
<option value="1" text="Gasolin" />
<option value="2" text="Diesel" />
<option value="3" text="E95" />
<option value="4" text="Hybrid" />
<option value="5" text="Electric" />
</fuel>
</car>
</data>
I am using Ajax to retrieve the data that i need from the xml document. Like this:
public string GetData(int typeOfData)
{
List<string> queryString = new List<string>();
switch (typeOfData)
{
case 1:
// Car->Milage
queryString.Add("car");
queryString.Add("milage");
break;
case 2:
// Car-Fuel
queryString.Add("car");
queryString.Add("fuel");
break;
}
// Now i need to construct a query to return the data, i have tried something like this:
var results = from data in db.Elements("data") where (queryString => db.Elements(test)) select new { ID = data.Attribute("value").Value, Name = data.Attribute("text").Value };
}
}
With XPath i could just simple make a string to query with, but how do i do this in linq?