I have XML file that looks like:
<Meal> <MealName>Lunch</MealName> <MealData>blahblahblah</MealData> <MealTime>2015-03-12</MealTime> </Meal> <Meal> <MealName>Dinner</MealName> <MealData>lolololol</MealData> <MealTime>2015-04-27</MealTime> </Meal>
I'd like to select MealName and MealData of the last Meal instance.
I can do everything else I need with simple LINQ queries just fine. For example, to get data from last week's meals, I do:
XElement noIdea = XElement.Load(".../.../meal.xml"); DateTime d = DateTime.Today.AddDays(-7); int offset = d.DayOfWeek - DayOfWeek.Monday; DateTime lastMonday = d.AddDays(-offset); DateTime lastSunday = lastMonday.AddDays(6); IEnumerable<XElement> idkMealTime = from el in noIdea.Elements("Meal") where DateTime.Compare(Convert.ToDateTime(el.Element("MealTime").Value), lastMonday) > 0 && DateTime.Compare(Convert.ToDateTime(el.Element("MealTime").Value), lastSunday) < 0 select el; WhatHaveYouEaten(idkMealTime);
But this one is different and I can't figure it out.
Help is appreciated.