65.9K
CodeProject is changing. Read more.
Home

Keyword Matching RSS Reader Control

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.38/5 (5 votes)

Apr 18, 2008

CPOL

2 min read

viewsIcon

60713

downloadIcon

177

Display RSS results that contain specific keywords.

Introduction

Using RSS feeds on web pages is a good way of creating dynamic content, which search engines love. The more your page changes, the more it gets crawled, and can affect your page rank.

However, just because you point your RSS reader to a feed, doesn't necessarily mean you'll get relevant content on that feed, a problem that is remedied by this control.

Background

This control came out of working on a similar control, RSS/XML Data-Binding to Data Control with Row Limitations.

Using the code

Using this control is quite simple. Simply place the code in your ~/Controls folder, drag it onto your .aspx page, and you're good to go. It does, however, require some configuration, usually in the PageLoad() method, either in the code-behind, or directly in your .aspx page.

Since we're interested in keyword matching, we provide the control with a list of keywords we would like to see in the RSS titles. Since one feed may not suffice, we can also provide a comma-delimited list of RSS sources (URLs) to retrieve content from.

RssReader1.SourceRss = 
            "http://news.google.com/news?hl=en&ned=us&" + 
            "amp;q=carbon+offset&ie=UTF-8&output=rss, http://news.go..."
RssReader1.TitleKeywords = "global warming,carbon footprint,global warming...
RssReader1.RowsToDisplay = 20;
RssReader1.Width = 300;
RssReader1.ShowLinks = true;
RssReader1.ShowTitles = true;
RssReader1.ShowDescriptions = false;
RssReader1.RowDivider = "";
RssReader1.UseTitleBullets = true;

Display

In the example above, we want to ensure that keywords such as {carbon footprint, biodeisel, global warming} exist... which, they do ;).

One great thing about this control is you could end up grabbing content and inserting RSS titles directly within paragraphs of your own content. This is achieved by setting ShowLinks=false, ShowTitles=true, ShowDescription=false. You would also probably want to limit the number of rows (RSS titles) to display down to one or two.

Displaying the contents of the control can be done in either a DataGrid or simple text, where you can display the results in a bulleted or non-bulleted format, configured through the UseTitleBullets parameter.

Title length

As in the example above, you may want to limit the length of the titles in order to fit in a given area. Setting the TitleLength parameter will truncate each title at the last word, adding " ..." at the end. What the control does not check for, however, is if any of your keywords exist in the non-truncated text. This is a simple thing to add if you really need to, but chances are that you don't want the titles to be too short, anyway.

Points of interest

Since you can provide an unlimited number of RSS source URLs, and the code has to scan through the content of each one, be vigilant of page load times - don't add too many URLs, as the delay will increase your page visitor's frustration, and possibly not even bother waiting for the page to load.

I've tested this with 15 URLs and a whole slew of keywords, and processing has been quite prompt.

History

None yet!

Don't forget to vote for this article!