Parsing a FeedBurner feed with jQuery

Parsing a FeedBurner feed with jQuery requires two components:

  1. a proxy to fetch the feed
  2. Ajax to parse the feed

Here's the proxy, written in PHP:

<?php
header('Content-Type: text/xml');

$feed = file_get_contents('http://feeds.feedburner.com/blogspot/onwebdev/');

echo $feed;

?>

Now we can add jQuery:

$(document).ready(function() {
    
        $('<ul></ul>').insertAfter('h1');
    
    
        $.get('proxy.php', function(data) {
        
        
            var $items = $(data).find('item');
            
            $items.each(function() {
            
                var html = '';
            
                var $item = $(this);
                
                var $title = $item.find('title').text();
                var raw_author = $item.find('author').text();
                
                var $author = raw_author.replace('gabriele.romanato@gmail.com', '').
                              replace('(', '').replace(')', '');
                              
                var $link = $item.find('author').next().next().text();
                
                var raw_date = $item.find('pubDate').text();
                var $pubdate = raw_date.replace('+0000', '');
                
                
                html += '<li><a href="' + $link + '">' + $title + '</a>' + '<div class="author">' + $author + '</div>' + 
        '<div class="pubdate">' + $pubdate + '</div>' + "</li>";

                $(html).appendTo('ul');
            
            });
        
        
        
        });
    
    
    });

There's only a difficult part here: selecting the feedburner:origLink element which has a namespace. To accomplish this task, we've used the next() method which returns the adjacent sibling of a given element. You can see the final result here.

Leave a Reply

Note: Only a member of this blog may post a comment.