//Parse private void ParseRSS() { try { XmlDocument rssXmlDoc = new XmlDocument(); // Load the RSS file from the RSS URL rssXmlDoc.Load(URL); //Store initial values - title and link XmlNode TL = rssXmlDoc.SelectSingleNode("rss/channel"); this.Title = TL.SelectSingleNode("title").InnerText.Trim(); this.Link = TL.SelectSingleNode("link").InnerText.Trim(); this.Description = TL.SelectSingleNode("description").InnerText.Trim(); this.Language = TL.SelectSingleNode("language").InnerText.Trim(); this.LastBuildDate = TL.SelectSingleNode("lastBuildDate").InnerText.Trim(); // Parse the Items in the RSS file XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item"); foreach (XmlNode rssNode in rssNodes) { //Title XmlNode rssSubNode = rssNode.SelectSingleNode("title"); string title = rssSubNode != null ? rssSubNode.InnerText : ""; //Link/Url rssSubNode = rssNode.SelectSingleNode("link"); string link = rssSubNode != null ? rssSubNode.InnerText : ""; link = ParseLink(link); //Description rssSubNode = rssNode.SelectSingleNode("description"); string description = rssSubNode != null ? rssSubNode.InnerText : ""; //Published date rssSubNode = rssNode.SelectSingleNode("pubDate"); string pubDate = rssSubNode != null ? rssSubNode.InnerText : ""; Titles.Add(title); URLs.Add(link); Descriptions.Add(description); PublishedDates.Add(pubDate); TitlesURLs.Add(title + " - " + link); Items.Add(new Item(title, link, description, pubDate)); } } catch (Exception e) { throw e; } }
//Parse private void ParseRSS() { try { XmlDocument rssXmlDoc = new XmlDocument(); // Load the RSS file from the RSS URL rssXmlDoc.Load(URL); //Store initial values - title and link XmlNode TL = rssXmlDoc.SelectSingleNode("rss/channel"); this.Title = TL.SelectSingleNode("title").InnerText.Trim(); this.Link = TL.SelectSingleNode("link").InnerText.Trim(); this.Description = TL.SelectSingleNode("description").InnerText.Trim(); this.Language = TL.SelectSingleNode("language").InnerText.Trim(); this.Copyright = TL.SelectSingleNode("copyright").InnerText.Trim(); this.PublishedDate = TL.SelectSingleNode("pubDate").InnerText.Trim(); // Parse the Items in the RSS file XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item"); XmlNamespaceManager dcMgr = new XmlNamespaceManager(rssXmlDoc.NameTable); dcMgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); foreach (XmlNode rssNode in rssNodes) { //Title XmlNode rssSubNode = rssNode.SelectSingleNode("title"); string title = rssSubNode != null ? rssSubNode.InnerText : ""; //Link/Url rssSubNode = rssNode.SelectSingleNode("link"); string link = rssSubNode != null ? rssSubNode.InnerText : ""; //Description rssSubNode = rssNode.SelectSingleNode("description"); string description = rssSubNode != null ? rssSubNode.InnerText : ""; //Published date rssSubNode = rssNode.SelectSingleNode("pubDate"); string pubDate = rssSubNode != null ? rssSubNode.InnerText : ""; //Creator rssSubNode = rssNode.SelectSingleNode("dc:creator", dcMgr); string creator = rssSubNode != null ? rssSubNode.InnerText : ""; //Date rssSubNode = rssNode.SelectSingleNode("dc:date", dcMgr); string date = rssSubNode != null ? rssSubNode.InnerText : ""; //Categories List <Item.Category> categories = new List <Item.Category>(); foreach (XmlNode c in rssNode.SelectNodes("category")) { categories.Add(new Item.Category(c.Attributes["domain"].Value, c.InnerText.Trim())); } Titles.Add(title); Links.Add(link); Descriptions.Add(description); PublishedDates.Add(pubDate); Creators.Add(creator); Dates.Add(date); TitlesLinks.Add(title + " - " + link); Items.Add(new Item(title, link, description, pubDate, creator, date, categories)); } } catch (Exception e) { throw e; } }