Feeds

Retrieving RSS/Atom Feeds with the Google AJAX Feed API

Using feeds to manage online news.

Secure remote control for conventional and virtual desktops

Receiving an Atom Feed

In this section, we’ll generate a JavaScript application to download and display an Atom feed for Reg Developer. First, obtain the URL for the Atom feed from the Reg Developer Feeds page.The URL for the Atom Feed “Reg Developer” is http://www.regdeveloper.co.uk/headlines.atom. To access a Feed with the Google AJAX Feed API we need to add the following <script> element to the JavaScript application GoogleRSS.html:

 <script type="text/javascript"
          src="http://www.google.com/jsapi?key=ABQIAAAAItAEL-H-
GuOHsDfD7MxmlhSpY8xpRlVNOvpHrXTaq4lZbJurjRQMBL0DtsRGauRDjwp6d-
ST2IgadQ"></script> 

The previous <script> tag loads the google.load function that is needed on order to load individual Google APIs. First, download version 1 of the feeds API:

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

Then create a JavaScript function initialize and specify the function to be invoked when the Google Feed API has loaded:

 google.setOnLoadCallback(initialize); 

Next, create a Feed class object to download a feed. Specify the URL for the Reg Developer Feed, to create the Feed class object:

 var feed = new google.feeds.Feed("http://www.regdeveloper.co.uk/headlines.atom");

Now, load the Atom feed using the load(callbackFunction) method of the Feed class:

 feed.load(function(result) {        });

Next, add a <div> element to the <body> element of the JavaScript application to display the Atom feed results:

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

Then, in the callback function obtain the <div> element using the getElementById method:

 var container = document.getElementById("feed");

Now, iterate over the feed results:

 for (var i = 0; i < result.feed.entries.length; i++) {       }

Then, obtain each of the feed entries, create a <div> element for each of the feed entries and add the entry title to the <div> element for each of the feed entry:

 var entry = result.feed.entries[i];           
 var div = document.createElement("div");            div.appendChild(document.createTextNode(entry.title)); 

And finally, add the <div> element for each of the entries to the container <div> element:

 container.appendChild(div); 

The JavaScript application GoogleRSS.html is available in the Resources zip file.

To display the Atom Feed entries’ titles, right-click on the GoogleRSS.html HTML page and select Run - see Figure 3:

Shows the JavaScript Applicationgeneration running.

The entries’ titles in the Atom feed are displayed – see Figure 4:

Shows the resulting Atom feed.

The previous Atom Feed application only displays the titles of the entries in the Atom feed. Next, we shall display additional JSON properties such as “title”, “link”, “publishedDate” and “contentSnippet” from the Atom Feed.

The essential guide to IT transformation

More from The Register

next story
The Return of BSOD: Does ANYONE trust Microsoft patches?
Sysadmins, you're either fighting fires or seen as incompetents now
Munich considers dumping Linux for ... GULP ... Windows!
Give a penguinista a hug, the Outlook's not good for open source's poster child
Intel's Raspberry Pi rival Galileo can now run Windows
Behold the Internet of Things. Wintel Things
Linux Foundation says many Linux admins and engineers are certifiable
Floats exam program to help IT employers lock up talent
Microsoft cries UNINSTALL in the wake of Blue Screens of Death™
Cache crash causes contained choloric calamity
Eat up Martha! Microsoft slings handwriting recog into OneNote on Android
Freehand input on non-Windows kit for the first time
Linux kernel devs made to finger their dongles before contributing code
Two-factor auth enabled for Kernel.org repositories
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Top 10 endpoint backup mistakes
Avoid the ten endpoint backup mistakes to ensure that your critical corporate data is protected and end user productivity is improved.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
Rethinking backup and recovery in the modern data center
Combining intelligence, operational analytics, and automation to enable efficient, data-driven IT organizations using the HP ABR approach.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.