/// <summary> /// Parses an RSS feed and returns a <see cref="IList&lt;Item&gt;"/>. /// </summary> public virtual async Task <IList <Item> > ParseRss(IResourceReader resourceReader) { try { var doc = await resourceReader.GetAsync(); // RSS/Channel/item var entries = from item in doc.Root.Descendants().First(i => i.Name.LocalName == "channel").Elements().Where(i => i.Name.LocalName == "item") select new Item { FeedType = FeedType.RSS, Content = item.Elements().First(i => i.Name.LocalName == "description").Value, Link = item.Elements().First(i => i.Name.LocalName == "link").Value, PublishDate = ParseDate(item.Elements().First(i => i.Name.LocalName == "pubDate").Value), Title = item.Elements().First(i => i.Name.LocalName == "title").Value }; return(entries.ToList()); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); } // Need to call dispose on the HttpClient object // when done using it, so the app doesn't leak resources return(null); }
/// <summary> /// Parses an Atom feed and returns a <see cref="IList&lt;Item&gt;"/>. /// </summary> public virtual async Task <IList <Item> > ParseAtom(IResourceReader resourceReader) { try { var doc = await resourceReader.GetAsync(); // Feed/Entry var entries = from item in doc.Root.Elements().Where(i => i.Name.LocalName == "entry") select new Item { FeedType = FeedType.Atom, Content = item.Elements().First(i => i.Name.LocalName == "content").Value, Link = item.Elements().First(i => i.Name.LocalName == "link").Attribute("href").Value, PublishDate = ParseDate(item.Elements().First(i => i.Name.LocalName == "published").Value), Title = item.Elements().First(i => i.Name.LocalName == "title").Value }; return(entries.ToList()); } catch { return(new List <Item>()); } }
/// <summary> /// Parses an RDF feed and returns a <see cref="IList&lt;Item&gt;"/>. /// </summary> public virtual async Task <IList <Item> > ParseRdf(IResourceReader resourceReader) { try { var doc = await resourceReader.GetAsync(); // <item> is under the root var entries = from item in doc.Root.Descendants().Where(i => i.Name.LocalName == "item") select new Item { FeedType = FeedType.RDF, Content = item.Elements().First(i => i.Name.LocalName == "description").Value, Link = item.Elements().First(i => i.Name.LocalName == "link").Value, PublishDate = ParseDate(item.Elements().First(i => i.Name.LocalName == "date").Value), Title = item.Elements().First(i => i.Name.LocalName == "title").Value }; return(entries.ToList()); } catch { return(new List <Item>()); } }