public override void ParseResults(XDocument xmlDoc, Exception error)
            {
                TripDetails tripDetail = new TripDetails();

                if (xmlDoc == null || error != null)
                {
                    callback(tripDetail, error);
                }
                else
                {
                    try
                    {

                        tripDetail =
                            (from trip in xmlDoc.Descendants("entry")
                             select ParseTripDetails(trip)).First();
                    }
                    catch (WebserviceResponseException ex)
                    {
                        error = ex;
                    }
                    catch (Exception ex)
                    {
                        error = new WebserviceParsingException(requestUrl, xmlDoc.ToString(), ex);
                    }
                }

                Debug.Assert(error == null);

                callback(tripDetail, error);
            }
            public void LocationForAddress_Completed(object sender, DownloadStringCompletedEventArgs e)
            {
                Exception error = e.Error;
                List<LocationForQuery> locations = null;

                try
                {
                    if (error == null)
                    {
                        XDocument xmlDoc = XDocument.Load(new StringReader(e.Result));

                        XNamespace ns = "http://schemas.microsoft.com/search/local/ws/rest/v1";

                        locations = (from location in xmlDoc.Descendants(ns + "Location")
                               select new LocationForQuery
                               {
                                   location = new GeoCoordinate(
                                       Convert.ToDouble(location.Element(ns + "Point").Element(ns + "Latitude").Value),
                                       Convert.ToDouble(location.Element(ns + "Point").Element(ns + "Longitude").Value)
                                       ),
                                    name = location.Element(ns + "Name").Value,
                                    confidence = (Confidence)Enum.Parse(
                                        typeof(Confidence),
                                        location.Element(ns + "Confidence").Value,
                                        true
                                        ),
                                   boundingBox = new LocationRect(
                                        Convert.ToDouble(location.Element(ns + "BoundingBox").Element(ns + "NorthLatitude").Value),
                                        Convert.ToDouble(location.Element(ns + "BoundingBox").Element(ns + "WestLongitude").Value),
                                        Convert.ToDouble(location.Element(ns + "BoundingBox").Element(ns + "SouthLatitude").Value),
                                        Convert.ToDouble(location.Element(ns + "BoundingBox").Element(ns + "EastLongitude").Value)
                                        )
                               }).ToList();

                    }
                }
                catch (Exception ex)
                {
                    error = new WebserviceParsingException(requestUrl, e.Result, ex);
                }

                Debug.Assert(error == null);

                callback(locations, error);
            }
            public override void ParseResults(XDocument xmlDoc, Exception error)
            {
                List<RouteSchedule> schedules = new List<RouteSchedule>();

                if (xmlDoc == null || error != null)
                {
                    callback(schedules, error);
                }
                else
                {
                    try
                    {
                        IDictionary<string, Route> routesMap = ParseAllRoutes(xmlDoc);

                        schedules.AddRange
                            (from schedule in xmlDoc.Descendants("stopRouteSchedule")
                             select new RouteSchedule
                             {
                                 route = routesMap[SafeGetValue(schedule.Element("routeId"))],

                                 directions =
                                     (from direction in schedule.Descendants("stopRouteDirectionSchedule")
                                      select new DirectionSchedule
                                      {
                                          tripHeadsign = SafeGetValue(direction.Element("tripHeadsign")),

                                          trips =
                                          (from trip in direction.Descendants("scheduleStopTime")
                                           select ParseScheduleStopTime(trip)).ToList<ScheduleStopTime>()
                                      }).ToList<DirectionSchedule>()

                             });
                    }
                    catch (Exception ex)
                    {
                        error = new WebserviceParsingException(requestUrl, xmlDoc.ToString(), ex);
                    }
                }

                Debug.Assert(error == null);

                callback(schedules, error);
                    }
            public override void ParseResults(XDocument xmlDoc, Exception error)
            {
                List<ArrivalAndDeparture> arrivals = new List<ArrivalAndDeparture>();

                if (xmlDoc == null || error != null)
                {
                    callback(arrivals, error);
                }
                else
                {
                    try
                    {
                        arrivals.AddRange(from arrival in xmlDoc.Descendants("arrivalAndDeparture")
                                          select ParseArrivalAndDeparture(arrival));
                    }
                    catch (Exception ex)
                    {
                        error = new WebserviceParsingException(requestUrl, xmlDoc.ToString(), ex);
                    }
                }

                Debug.Assert(error == null);

                callback(arrivals, error);
            }
            public override void ParseResults(XDocument xmlDoc, Exception error)
            {
                List<RouteStops> routeStops = new List<RouteStops>();

                if (xmlDoc == null || error != null)
                {
                    callback(routeStops, error);
                }
                else
                {
                    try
                    {
                        IDictionary<string, Route> routesMap = ParseAllRoutes(xmlDoc);

                        // parse all the stops, using previously parsed Route objects
                        IList<Stop> stops =
                            (from stop in xmlDoc.Descendants("stop")
                             select ParseStop(stop,
                                 (from routeId in stop.Element("routeIds").Descendants("string")
                                  select routesMap[SafeGetValue(routeId)]
                                      ).ToList<Route>()
                             )).ToList<Stop>();

                        IDictionary<string, Stop> stopsMap = new Dictionary<string, Stop>();
                        foreach (Stop s in stops)
                        {
                            stopsMap.Add(s.id, s);
                        }

                        // and put it all together
                        routeStops.AddRange
                            (from stopGroup in xmlDoc.Descendants("stopGroup")
                             where SafeGetValue(stopGroup.Element("name").Element("type")) == "destination"
                             select new RouteStops
                             {
                                 name = SafeGetValue(stopGroup.Descendants("names").First().Element("string")),
                                 encodedPolylines = (from poly in stopGroup.Descendants("encodedPolyline")
                                                     select new PolyLine
                                                     {
                                                         pointsString = SafeGetValue(poly.Element("points")),
                                                         length = SafeGetValue(poly.Element("length"))
                                                     }).ToList<PolyLine>(),
                                 stops =
                                     (from stopId in stopGroup.Descendants("stopIds").First().Descendants("string")
                                      select stopsMap[SafeGetValue(stopId)]).ToList<Stop>(),

                                 route = routesMap[routeId]

                             });
                    }
                    catch (WebserviceResponseException ex)
                    {
                        error = ex;
                    }
                    catch (Exception ex)
                    {
                        error = new WebserviceParsingException(requestUrl, xmlDoc.ToString(), ex);
                    }
                }

                Debug.Assert(error == null);

                // Remove a page from the cache if we hit a parsing error.  This way we won't keep
                // invalid server data in the cache
                if (error != null)
                {
                    directionCache.Invalidate(new Uri(requestUrl));
                }

                callback(routeStops, error);
            }
            public override void ParseResults(XDocument xmlDoc, Exception error)
            {
                List<Stop> stops = new List<Stop>(); ;
                bool limitExceeded = false;

                if (xmlDoc == null || error != null)
                {
                    callback(stops, limitExceeded, error);
                }
                else
                {
                    try
                    {
                        IDictionary<string, Route> routesMap = ParseAllRoutes(xmlDoc);

                        stops.AddRange(from stop in xmlDoc.Descendants("stop")
                                       select ParseStop(
                                       stop,
                                       (from routeId in stop.Element("routeIds").Descendants("string")
                                        select routesMap[SafeGetValue(routeId)]).ToList<Route>()));                                        

                        IEnumerable<XElement> descendants = xmlDoc.Descendants("data");
                        if (descendants.Count() != 0)
                        {
                            limitExceeded = bool.Parse(SafeGetValue(descendants.First().Element("limitExceeded")));
                        }

                        Debug.Assert(limitExceeded == false);
                    }
                    catch (WebserviceResponseException ex)
                    {
                        error = ex;
                    }
                    catch (Exception ex)
                    {
                        error = new WebserviceParsingException(requestUrl, xmlDoc.ToString(), ex);
                    }
                }

                Debug.Assert(error == null);

                // Remove a page from the cache if we hit a parsing error.  This way we won't keep
                // invalid server data in the cache
                if (error != null)
                {
                    stopsCache.Invalidate(new Uri(requestUrl));
                }

                callback(stops, limitExceeded, error);
            }
            public override void ParseResults(XDocument xmlDoc, Exception error)
            {
                List<Route> routes = new List<Route>();
                if (xmlDoc == null || error != null)
                {
                    callback(routes, error);
                }
                else
                {
                    try
                    {
                        routes.AddRange(from route in xmlDoc.Descendants("route")
                                        select ParseRoute(route, xmlDoc.Descendants("agency")));
                    }
                    catch (Exception ex)
                    {
                        error = new WebserviceParsingException(requestUrl, xmlDoc.ToString(), ex);
                    }

                    Debug.Assert(error == null);

                    callback(routes, error);
                }
            }