Feeds

Retrieving RSS/Atom Feeds with the Google AJAX Feed API

Using feeds to manage online news.

Remote control for virtualized 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.

Internet Security Threat Report 2014

More from The Register

next story
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
You stupid BRICK! PCs running Avast AV can't handle Windows fixes
Fix issued, fingers pointed, forums in flames
NSA SOURCE CODE LEAK: Information slurp tools to appear online
Now you can run your own intelligence agency
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
prev story

Whitepapers

Choosing cloud Backup services
Demystify how you can address your data protection needs in your small- to medium-sized business and select the best online backup service to meet your needs.
Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Designing and building an open ITOA architecture
Learn about a new IT data taxonomy defined by the four data sources of IT visibility: wire, machine, agent, and synthetic data sets.
10 threats to successful enterprise endpoint backup
10 threats to a successful backup including issues with BYOD, slow backups and ineffective security.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?