[My Blog] | [Code Projects Home] | [skmMenu] | [RssFeed]

RssFeed Demo :: RssEngine

This demo illustrates using RssFeed's RssEngine class to programmatically work with the contents of a feed. Specifically, it allows you to enter an RSS feed and a term to search for; it then slurps down the feed and searches each item for the substring you provided, displaying those items with a match. Note that in the matched instances, the result is highlighted yellow. See this FAQ for more information...


Enter RSS feed URL:  
Enter Term to Search:  


Source Code

<%@ Import Namespace="skmRss.Engine" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>

<form id="Form1" method="post" runat="server">		
	<P>Enter RSS feed URL:
		<asp:TextBox id="url" runat="server" Columns="45">http://aspnet.4guysfromrolla.com/rss/rss.aspx</asp:TextBox> <br />
		Enter Term to Search:
		<asp:TextBox id="searchFor" runat="server">ASP.NET</asp:TextBox> <br />
		<asp:Button OnClick="SearchForMatches" id="btnGetStats" runat="server" Text="Search Feed"></asp:Button></P>

		<asp:Label id="matches" runat="server"></asp:Label></P>
</form>

<script language="C#" runat="server">

void SearchForMatches(object sender, EventArgs e)
{
	RssEngine engine = new RssEngine();
	RssDocument doc = engine.GetDataSource(url.Text, 10000);
	
	Regex re = new Regex(@"\b(ASP\.NET)\b");
	
	// See if there are any instances of "ASP.NET" in the items' descriptions	
	matches.Text = "<p> </p><h2>Matching Results</h2>";
	foreach (RssItem item in doc.Items)
    if (item.Description.IndexOf("ASP.NET") >= 0)
      matches.Text += string.Format("<b>{0}</b>:<br />{1}<p><hr /></p>", item.Title, re.Replace(item.Description, "<span style=\"background-color:yellow;\">$1</span>"));
}

</script>	

[Return to the article...] | [Return to the RssFeed Page...]