public Item(RssItem item) { this.title = item.Title; this.description = item.Description; this.url = item.Link; this.guid = item.Guid; this.pub_date = item.PubDate; }
private bool checkInDataGridView(RssItem item) { foreach (DataGridViewRow row in newsTable.Rows) { if (((string)row.Cells["Title"].Value == item.title) && ((string)row.Cells["Link"].Value == item.link)) { return(false); } } return(true); }
private List <RssItem> parse(string channelUrl) { try { XmlDocument doc = new XmlDocument(); doc.Load(channelUrl); XmlNode channel = doc.ChildNodes[1].FirstChild; List <RssItem> rssItems = new List <RssItem>(); RssItem rssItem; foreach (XmlNode item in channel.SelectNodes("item")) { if (checkItemOfFilters(item)) { rssItem = new RssItem( item.SelectSingleNode("title").InnerText, item.SelectSingleNode("link").InnerText, regex.Replace(item.SelectSingleNode("description").InnerText, ""), item.SelectSingleNode("category") != null ? item.SelectSingleNode("category").InnerText : "", item.SelectSingleNode("pubDate").InnerText ); lock (this) { newsTable.Invoke(new Action(() => { if (checkInDataGridView(rssItem)) { int rowNumber = newsTable.Rows.Add(); newsTable.Rows[rowNumber].Cells["Title"].Value = rssItem.title; newsTable.Rows[rowNumber].Cells["Category"].Value = rssItem.category; newsTable.Rows[rowNumber].Cells["Description"].Value = rssItem.description; newsTable.Rows[rowNumber].Cells["PubDate"].Value = rssItem.publicDate; newsTable.Rows[rowNumber].Cells["Link"].Value = rssItem.link; newsTable.Rows[rowNumber].Cells["ID"].Value = newsTable.Rows.Count; } })); } rssItems.Add(rssItem); } } return(rssItems); } catch (Exception exc) { MessageBox.Show(exc.Message); return(null); } }
// reads the channel section of an rss document void readChannel(XmlNodeList node_list) { foreach (XmlNode node in node_list) { switch (node.Name.ToLower ()) { case "title": title = node.InnerText; break; case "link": link = node.InnerText; break; case "description": description = node.InnerText; break; case "pubdate": pubdate = node.InnerText; break; case "item": RssItem item = new RssItem (node.ChildNodes); items.Add (item); break; } } }
public bool GetItems(string sourceName) { try { XmlDocument doc = new XmlDocument(); doc.Load(new XmlTextReader(sourceName)); XmlNode root = doc.DocumentElement; articles = new RssItem[root.SelectNodes("channel/item").Count]; XmlNodeList nodeList = root.ChildNodes; int count = 0; foreach (XmlNode channel in nodeList) { foreach (XmlNode channel_item in channel) { switch (channel_item.Name) { case "title": rssChannel.title = channel_item.InnerText; break; case "description": rssChannel.description = channel_item.InnerText; break; case "link": rssChannel.link = channel_item.InnerText; break; case "copyright": rssChannel.copyright = channel_item.InnerText; break; case "image": XmlNodeList imgList = channel_item.ChildNodes; foreach (XmlNode imgItem in imgList) { switch (imgItem.Name) { case "url": imageChanel.imgURL = imgItem.InnerText; break; case "link": imageChanel.imgLink = imgItem.InnerText; break; case "title": imageChanel.imgTitle = imgItem.InnerText; break; } } break; case "item": XmlNodeList itemsList = channel_item.ChildNodes; articles[count] = new RssItem(); foreach (XmlNode item in itemsList) { switch (item.Name) { case "title": articles[count].title = item.InnerText; break; case "link": articles[count].link = item.InnerText; break; case "description": articles[count].description = item.InnerText; break; case "pubDate": articles[count].pubData = item.InnerText; break; } } ++count; break; } } } return(true); } catch (Exception ex) { return(false); } }