C# finding data in xml file between 2 dates

oRELLY

New Member
Ok so i got help from someone who helped me find an average of distance from an xml file within two dates from a particular user and from a particular placeHere is the code \[code\] public string GetData(string userName, DateTime fromDate, DateTime toDate){ var userElement = xDox.Descendants("User") .SingleOrDefault(u => u.Element("Name").Value =http://stackoverflow.com/questions/12688003/= userName);var builder = new StringBuilder();if (userElement != null){ var result = userElement.Descendants("Attempts") .Select(a => new { Place = a.Element("Place").Value, Date = DateTime.Parse(a.Element("Date").Value), Distance = int.Parse(a.Element("Distance").Value) }) .Where(a => a.Date >= fromDate && a.Date <= toDate) .GroupBy(a => a.Place) .Select(g => new {Place = g.Key, Avg = g.Average(x => x.Distance)}); builder.AppendFormat("User:{0}", userName); builder.AppendLine(); builder.AppendFormat("Date:{0} to {1}", fromDate, toDate); builder.AppendLine(); foreach (var item in result) { builder.AppendFormat("Average Distance in {0}: {1}", item.Place, item .Avg); builder.AppendLine(); } } return builder.ToString();}\[/code\]It will give me a result such like this\[quote\] User:David from 9/2/2012 to 10/1/2012 Average Distance in Paris: 30 Average Distance in Madrid: 45.5\[/quote\]How could i add to this code so besides finding an average it will also give me all the data of the particular user withing those two dates, for example\[quote\] User:David from 9/2/2012 to 10/1/2012 Run1: Distance in Madrid:30 Run2: Distance in Paris:20 Run3: Distance in Paris:50\[/quote\]and so on.. How could you also add total runs, for example in this case 3
 
Back
Top