Reading a RSS Feed using Google Ajax Feed API

Hi,

In the project I’m currently working we had a requirement to display some news that comes from a External RSS Feed. At the beginning we choose an Server side approach, using the Rome framework to read the RSS Feed, but we faced some problems with proxy settings. So we needed to change our approach from server side to  client side.

For a client side approach we needed to use ajax, but using ajax we faced another problem when we tried to make a request to another domain.  So a guy from our team found the Google Ajax Feed API, a javascript API that allow us to read RSS Feeds in a very simple way.

Below there is a simple example got from the API page.

<html>
  <head>
    <script type="text/javascript" src="http://www.google.com/jsapi?key=<em>YOUR_KEY_HERE</em>"></script>
    <script type="text/javascript">

    google.load("feeds", "1");

    function initialize() {
      var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
      feed.load(function(result) {
        if (!result.error) {
          var container = document.getElementById("feed");
          for (var i = 0; i < result.feed.entries.length; i++) {
            var entry = result.feed.entries[i];
            var div = document.createElement("div");
            div.appendChild(document.createTextNode(entry.title));
            container.appendChild(div);
          }
        }
      });
    }
    google.setOnLoadCallback(initialize);

    </script>

  </head>
  <body>
    <div id="feed"></div>
  </body>
</html>

You can find other examples in the API page.

Enjoy it!

Thanks