erikabuffalo
New Member
I need help filtering xml file according to dates , with this part of the code that i have it only prints out all average information according to user name and place\[code\] Runner run = new Runner(); string user = comboBox5.SelectedItem.ToString(); string filePaths = "runners.xml"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filePaths); XDocument xDoc = XDocument.Load(filePaths); var averageAddDistancequery = xDoc.Descendants("User").Where(w => (string)w.Element("Name") == user).Select(s => new { add = s.Elements("Attempts").Where(w => (string)w.Element("Place").Value =http://stackoverflow.com/questions/12684213/="Paris").Select(t => t.Element("Distance").Value) }).ToList(); if (averageAddDistancequery[0].add.Count() > 0) { var aa = averageAddDistancequery[0].add.Average(a => float.Parse(a)); run.averageDistance = aa.ToString(); } else { // nothing } var averageAdd2Distancequery = xDoc.Descendants("User").Where(w => (string)w.Element("Name") == userSelector).Select(s => new { add = s.Elements("Attempts").Where(w => (string)w.Element("Place").Value =http://stackoverflow.com/questions/12684213/="Madrid").Select(t => t.Element("Distance").Value) }).ToList(); if (averageAdd2Distancequery[0].add.Count() > 0) { var aa = averageAdd2DistanceSubquery[0].add.Average(a => float.Parse(a)); run.averageDistance2 = aa.ToString(); } else { // nothing } xmlDoc.DocumentElement.SetAttribute("searching", user); XmlNodeList tests = xmlDoc.SelectNodes("//User[Name =/*/@searching]/Attempts"); listBox1.Items.Clear(); listBox1.Items.Add("Runners Name: " + user); listBox1.Items.Add("Overall Distance in Paris: " + run.averageAdd); listBox1.Items.Add("Overall Distance in Madrid: " + run.averageSub);\[/code\]For example if my xml file looks like this\[code\] Users> <User> <Name>David</Name> <Attempts> <Place>Paris</Place> <Date>3/29/2012</Date> <Distance>100</Distance> </Attempts> <Attempts> <Place>Madrid</Place> <Date>7/28/2012</Date> <Distance>100</Distance> </Attempts> <Attempts> <Place>Paris</Place> <Date>8/19/2012</Date> <Distance>60</Distance> </Attempts> <Attempts> <Place>Madrid</Place> <Date>9/29/2012</Date> <Distance>200</Distance> </Attempts> </User> <User> <Name>Lenny</Name> <Attempts> <Place>Paris</Place> <Date>9/29/2012</Date> <Distance>130</Distance> </Attempts> </User> </Users>\[/code\]If i run the code for david it will print out something like thisUseravidAverage Distance in Paris: Average Distance in Madrid:This is not what i want, what i want is to select any two dates lets from a textbox and display only the information between those two datesFor example if i chose david, from date 3/29/2012 to 8/29/2012I would want and output something like this:User: DavidAverage Distance in Paris from 3/29/2012 to 8/29/2012: Average Distance in Madrid from 3/29/2012 to 8/29/2012: Ive been trying for hours, i need help implementing this