[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1785
  • Last Modified:

JavaScript to parse and display an RSS feed

Hi all,

Does anybody know of a good tutorial where I can learn how to use JavaScript/Ajax to parse and display a RSS feed.

The site I wish to display the RSS feed on is on a hosted CMS and I CANNOT use server side scripting such as PHP. I am stuck with using client side scripting mainly JavaScript.

I have seen this done and have had a look around. However the options I have come across either invlove using a service to parse it for you and then it'll pass it to your site, or it contains some sort of branding/restrictions on display, etc..

The RSS feed which I'm interesed in parsing is http://rss.weather.com.au/qld/airlie-beach

I want to be able to display today's weather and tomorrows forecast. I also want full control over how it is displayed and ideally I would like all of the JS scripts to be hosted on the CMS so that the solution is between my site and the RSS feed. I don't want a 3rd party service in between.

Can anyone point me in the right direction or provide me with some demo code??

Thanks in advance.

GW.
0
GhostWerx
Asked:
GhostWerx
  • 4
  • 2
2 Solutions
 
khsaterCommented:
If you're into jQuery check this out: http://www.hovinne.com/blog/index.php/2007/07/15/132-jfeed-jquery-rss-atom-feed-parser-plugin
I can't vouch for it, but you might be able to make use of it.  jQuery is pretty bulky if you just want to use this, though.
0
 
GhostWerxAuthor Commented:
Hi,

I checked out jFeed. It appears to be what I want.

When I placed the test script on my page it worked fine.

However when I tried plugging the feed from http://rss.weather.com.au/qld/airlie-beach into it, it seems to fail to see it as a feed and doesn't parse it.

Any suggestions as to what I'm doing wrong or do I need to specify something else??

Thanks in advance.

GW.
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.jfeed.pack.js"></script>
<script type="text/javascript">
 
jQuery(function() {
 
    jQuery.getFeed({
        url: 'http://rss.weather.com.au/qld/airlie-beach',
        success: function(feed) {
        
            jQuery('#result').append('<h2>'
            + '<a href="'
            + feed.link
            + '">'
            + feed.title
            + '</a>'
            + '</h2>');
            
            var html = '';
            
            for(var i = 0; i < feed.items.length && i < 5; i++) {
            
                var item = feed.items[i];
                
                html += '<h3>'
                + '<a href="'
                + item.link
                + '">'
                + item.title
                + '</a>'
                + '</h3>';
                
                html += '<div class="updated">'
                + item.updated
                + '</div>';
                
                html += '<div>'
                + item.description
                + '</div>';
            }
            
            jQuery('#result').append(html);
        }    
    });
});
 
</script>

Open in new window

0
 
Ray PaseurCommented:
I assume you have seen this notice embedded in the RSS and your intended application is in compliance with it.

<!-- Weather.com.au RSS Feed must be used in accordance with the terms and conditions listed at http://www.weather.com.au/about/rss -->

Can you tell us what prevents you from using PHP to parse this?  It would be very easy to access either the CDATA descriptions or the w:current and w:forecast RSS Extension fields via SimpleXML.  Note that the DTD is 404, but that should not be an issue for PHP - it might be causing jFeed some trouble (but that is just speculation).

You might also contact Weather.com.au and find out if they have addressed this issue before.  They may have the background information to point you in the right direction quickly.

best regards, ~Ray

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GhostWerxAuthor Commented:
Hi all,

Sorry I have left this one for so long.

I cannot use PHP or any server side scripting to parse the rss feed due to the CMS/Hosting the website is on.

The jFeed reads the example xml file fine. But if I try changing it to an rss feed it doesn't work.

Are there any further ideas. Is there something else I can try that might help find out what isn't working?

Thanks GW.
0
 
Ray PaseurCommented:
What CMS and Hosting is the web site on?  Perhaps if we know that we can suggest something.  

Did you contact Weather.com.au yet?  What were they able to tell you?

Since you suggested AJAX and also said you cannot use PHP, I am left to wonder...
0
 
GhostWerxAuthor Commented:
Hi Ray Paseur and khsater,

Just to clear a couple of things up.

Your correct I did mention AJAX when I shouldn't have. That was my error. Sorry for the confusion.

FYI: The site is hosted on the GoodBarry/Business Catalyst CMS. http://goodbarry.com/ http://businesscatalyst.com/

Also sorry for leaving this thread open for so long, but the project in question wasn't a very high priority.

I finally got it working. I had a friend take a look. Apparently some other hack JS I had on the page was clashing with jQuery.

Anyways it's all sorted. Thank you for your help.

GW.

0
 
GhostWerxAuthor Commented:
Thanks for your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now