
复制usingSystem.Collections.Generic; usingSystem; usingSystem.Net; usingSystem.Xml.Linq; usingSystem.Linq; usingSystem.Windows; usingMicrosoft.Maps.MapControl; namespaceGeoRss.Map.GeoRssUtils { publicdelegatevoidDownloadGeoRssCompletedEventHandler(List<GeoRssItem>items); publicdelegatevoidDownloadGeoRssExceptionEventHandler(Exceptione); publicclassGeoRssReader { publicGeoRssReader() { wc=newWebClient(); wc.DownloadStringCompleted+=WebClientDownloadGeoRssCompleted; } publicGeoRssReader(Uriuri) :this() { this.uri=uri; } publicGeoRssReader(Uriuri,间应间数据DownloadGeoRssCompletedEventHandlerevh) :this(uri) { DownloadGeoRssCompleted+=evh; } publicUriuri{get;set;} publiceventDownloadGeoRssCompletedEventHandlerDownloadGeoRssCompleted; publiceventDownloadGeoRssExceptionEventHandlerDownloadGeoRssException; publicvoidReadAsync() { if(DownloadGeoRssCompleted.Target!=null) { wc.DownloadStringAsync(uri); } } #region_private privatereadonlyWebClientwc; privatevoidWebClientDownloadGeoRssCompleted(objectsender,DownloadStringCompletedEventArgse) { try { XNamespacensXml="http://www.w3.org/2005/Atom"; XNamespacensGeorss="http://www.georss.org/georss"; XNamespacensGeo="http://www.w3.org/2003/01/geo/wgs84_pos#"; XNamespacensMedia="http://search.yahoo.com/mrss/"; varitems=fromiteminXElement.Parse(e.Result).Descendants("item") selectnewGeoRssItem { Title=(item.Element("title")!=null)?item.Element("title").Value:null, Link=(item.Element("link")!=null)?item.Element("link").Value:null, Description=(item.Element("description")!=null)?item.Element("description").Value:null, PubData=(item.Element("pubDate")!=null)?item.Element("pubDate").Value:null, Locatios=ParserLocations(XElement.Parse(item.LastNode.ToString().Replace(":","X")).Value) }; if(DownloadGeoRssCompleted.Method!=null) { DownloadGeoRssCompleted.Invoke(items.ToList()); } } catch(Exceptionex) { if(DownloadGeoRssException.Method!=null) { DownloadGeoRssException.Invoke(ex); } else { throw; } } } privateLocationCollectionParserLocations(stringpoints) { LocationCollectionlc=newLocationCollection(); string[]ps=points.Split(); for(inti=0;i<ps.Length;i+=2) { lc.Add(newLocation(double.Parse(ps[i]),double.Parse(ps[i+1]))); } returnlc; } #endregion } } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.