jQuery: Parse RSS Feed


/ Published in: jQuery
Save to your folder(s)

Here's a simple example of how to parse RSS feeds using jQuery. You will need jFeed (http://www.hovinne.com/blog/index.php/2007/07/15/132-jfeed-jquery-rss-atom-feed-parser-plugin) and a bit of help from PHP (http://snipplr.com/view/12467/php-capture-rss-feed/)


Copy this code and paste it in your HTML
  1. <script type="text/javascript" src="./js/jquery/jquery.js"></script>
  2. <script type="text/javascript" src="./js/jFeed/build/dist/jquery.jfeed.pack.js"></script>
  3. <script type="text/javascript">
  4. function loadFeed(){
  5. $.getFeed({
  6. url: 'proxy.php?url=http://locationofrssfeed/',
  7. success: function(feed) {
  8.  
  9. //Title
  10. $('#result').append('<h2><a href="' + feed.link + '">' + feed.title + '</a>' + '</h2>');
  11.  
  12. //Unordered List
  13. var html = '<ul>';
  14.  
  15. $(feed.items).each(function(){
  16. var $item = $(this);
  17. //trace( $item.attr("link") );
  18. html += '<li>' +
  19. '<h3><a href ="' + $item.attr("link") + '" target="_new">' + $item.attr("title") + '</a></h3> ' +
  20. '<p>' + $item.attr("description") + '</p>' +
  21. // '<p>' + $item.attr("c:date") + '</p>' +
  22. '</li>';
  23. });
  24.  
  25. html += '</ul>';
  26.  
  27. $('#result').append(html);
  28. }
  29. });
  30. }
  31. <script type="text/javascript">

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.