public static GeoRSSSource ParseGeoRSSXml(string xmlGeoRSS, string filter, bool toMercator) { GeoRSSSource rssSource = new GeoRSSSource(); XDocument xmlDoc = XDocument.Parse(xmlGeoRSS, LoadOptions.None); IEnumerable <XElement> children = null; switch (xmlDoc.Root.Name.LocalName.ToLower()) { case "rss": XElement channelElem = ((XElement)xmlDoc.Root.FirstNode); children = channelElem.Elements(); rssSource.SourceType = GeoRSSSourceType.RSS; break; case "feed": children = xmlDoc.Root.Elements(); rssSource.SourceType = GeoRSSSourceType.ATOM; break; } foreach (XElement elem in children) { switch (elem.Name.LocalName.ToLower()) { case "title": rssSource.Title = elem.Value; break; case "link": rssSource.Link = (elem.HasAttributes) ? elem.FirstAttribute.Value : elem.Value; break; case "summary": case "content": case "description": rssSource.Description = elem.Value; break; case "pubdate": case "updated": DateTime pubdate; DateTime.TryParse(elem.Value, out pubdate); rssSource.pubDate = pubdate; break; case "item": case "entry": GeoRSSItem item = ParseGeoRSSItem(elem, toMercator); bool containKey = string.IsNullOrEmpty(filter) ? true : item.Title.Contains(filter); if (containKey) { rssSource.Items.Add(item); } break; } } return(rssSource); }
private void RSSClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { string xmlRSS = e.Result; if (!string.IsNullOrEmpty(xmlRSS)) { GeoRSSSource rssSource = GeoRSSHelper.ParseGeoRSSXml(xmlRSS, widgetConfig.Filter, GeometryTool.IsWebMercatorSR(this.MapSRWKID)); ListGeoRSSItems.ItemsSource = rssSource.Items; if (this.Visibility == Visibility.Visible) { AddGeoRSSGraphics(rssSource.Items); } } this.IsBusy = false; }