Pick element from xml



I have this code to pick up foods and foodplaces from XML Att first i have stored the name of each restuarnt in a string list and i want to pick the food that this restaurants in the lists reservs



foreach(var restaurant in restaurants)
{
List<foodplace> foodPlaces = (from _foodplaces in xmlDocument.Element("foodplaces").Elements("foodplace")
where _foodplaces.Value == restaurant
select new foodplace
{
day = (from day in _foodplaces.Elements(thisDay)
let list = day.Elements("food").Take(3).ToList()
select new DayOfWeek
{
food1 = (list.Count > 0 ? list[0].Value : string.Empty),
food2 = (list.Count > 1 ? list[1].Value : string.Empty),
food3 = (list.Count > 2 ? list[2].Value : string.Empty)
}).FirstOrDefault()
}).ToList();


The problem is that _foodplaces returns value from xmldoxument that lookslike this



\n\n\n\t the litle inddian \t\n\n\n


and the restuarant value is a string looks like this "the litle indian"


and so the linq statement returns null becuse _foodplace is not restuarant how to come arround this


No comments:

Post a Comment