RSS feed using JavaScript – Cont’d

JsonDuit turned out to be a failed experiment, mainly because they insist on linking to the feed “widget” created on their website.
What I was looking for was a way to make a cross domain request which would fetch the RSS XML and I could parse it. Turns out solution 3 from my earlier post was the way to go. To implement this is extremely simple. First include the yui file:

Once this is done, its easy to use it anywhere in the project:

YUI().use('yql', function(Y) {
Y.YQL('select title from rss where url=""', function(r) {
  var items = r.query.results.item;
  dojo.forEach(items, function(data){
    //do something                        

To experiment with YQL queries, use the YQL console here.

Reading RSS feed using JavaScript

I have an idea in mind to build a simple introductory website for myself and one of the things I wanted on the front page of that website was a RSS feed type of thing on the front page. This way I could link to this existing blog link and not have to deal with moving my blog to a new domain, etc.

Anyway, surprisingly, few solutions exist to read a blog’s feed(which is XML) and do things with it using JavaScript.

Things I tried:

1. Looked at WordPress to see if it provided a JavaScript API. It doesn’t.

2. Since I use Dojo for all my JavaScript programming, I looked at to make a cross domain Ajax call and then use the response to extract what I want out of the feed.
Turns out only can handle JSON responses. So this fails as a solution.

3. YUI combined with YQL is a possible solution. I could use YQL to query the feed and then use YUI to read that result. Not bad. Definitely a solution.

4. Then I found JSonduit. Seems to be written just to solve my problem 🙂 How does this work?

You include this JS file:

And then, call the following function:

JSonduit.feed.load(feedId, 0, function(data) {
if (data.error) {
alert("Feed Error: " + data.error.error + " : " + data.error.desc);
else {
//do something with the result

Read up here for more information about this and some sample code.