rsssyndication

Bring freshly updated content to web site


What technology can be used on my website to bring in daily fresh updated content, like News RSS feed from a famous news website,... etc?


Solution

  • [Update - General answer]

    As you already mention, RSS feeds are your best way to get updated news. They are easily consumable and provide a standard interface for article based data. For example CNN has their top storries at http://rss.cnn.com/rss/cnn_topstories.rss. When browsing news sites with Firefox it will display a RSS icon in the addressbar if the site has RSS feeds, which makes it easier to discover feeds.


    Since you tag this as C# and ASP.Net I will answer it in terms of coding.

    Many news sites offer RSS feeds and these can be consumed with the SyndicationFeed class introduced in .Net 3.5. The SyndicationFeed class supports both Atom 1.0 and RSS 2.0.

    The most important part when consuming feeds in my opinion is to cache them, so that you don't download the feed for every hit on your web page. Where you get your feed from depends on what topics you want and where in the world you are located.

    Here's a short example.

    // Check cache for data
    IEnumerable<SyndicationItem> items = Cache["NewsFeed"] as IEnumerable<SyndicationItem>;
    if (items == null)
    {
        // Not in cache, go get it!
        try
        {
            SyndicationFeed news = SyndicationFeed.Load(XmlReader.Create("http://www.news.corp/feed.xml"));
            items = news.Items;
        }
        catch
        {
            items = new List<SyndicationItem>();
        }
        // Add the items to the cache
        Cache.Insert("NewsFeed", items, null, DateTime.Now.AddHours(1.0), TimeSpan.Zero);
    }
    // Bind your data somewhere