Feeds

Retrieving RSS/Atom Feeds with the Google AJAX Feed API

Using feeds to manage online news.

Securing Web Applications Made Simple and Scalable

You now iterate over the entries to obtain each of the entries in the Atom Feed. Specify the attributes to be displayed:

 var attributes = ["title", "link", "publishedDate", "contentSnippet"];

Then, create a <div> element for each of the attributes and add the <div> elements to the container <div> element:

 for (var j = 0; j < attributes.length; j++) {
        var div = document.createElement("div");
        div.appendChild(document.createTextNode(entry[attributes[j]]));
        container.appendChild(div);
      }

The JavaScript application, GoogleRSS-JSON.html, to display the JSON properties from the Atom Feed is available in the Resources zip file.

Run the GoogleRSS-JSON.html application. The Atom Feed entries’ titles, links, publication date, and content snippet are displayed – see Figure 5:

Shows the Atom feed with JSON Properties.

Next, we shall display multiple feeds using the FeedControl class. We’ll display the “Reg Developer” Atom feed and the “Editors Blog” Atom feed. As in the JavaScript application, to display a single feed specify a <script> tag for the Google Feed APIs. Add a <div> element to the JavaScript application to display the Atom Feeds:

 <body><div id="feedControl">Loading</div></body> 

Load version 1 of the Feed API. Invoke a callback function initialize after the Google Feed API has loaded. In the callback function create a FeedControl object:

 var feedControl = new google.feeds.FeedControl();

Specify the Atom Feeds to be loaded by the FeedControl:

 feedControl.addFeed("http://www.regdeveloper.co.uk/headlines.atom", "Reg Developer");
feedControl.addFeed("http://www.regdeveloper.co.uk/editors_blog/headlines.atom", 
"Editors Blog");

Load the Atom Feeds and display the Atom Feeds using the draw method:

 feedControl.draw(document.getElementById("feedControl"));

The JavaScript application, GoogleRSS-MultipleFeeds.html, to load multiple Atom Feeds is available in the Resources zip file. Now run the JavaScript application, and multiple Atom feeds are displayed – see Figure 6:

Shows multiple feeds.

You should now have successfully received an Atom feed. As it happens, the applications in this article may be used with either an Atom 1.0 feed or an RSS 2.0 feed (we’ve used Atom 1.0). However, the url for RSS 2.0 would be different: instead of http://www.regdeveloper.co.uk/headlines.atom, it would be http://www.regdeveloper.co.uk/headlines.rss. ®

Bridging the IT gap between rising business demands and ageing tools

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
Mozilla fixes CRITICAL security holes in Firefox, urges v31 upgrade
Misc memory hazards 'could be exploited' - and guess what, one's a Javascript vuln
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
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 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
Seven Steps to Software Security
Seven practical steps you can begin to take today to secure your applications and prevent the damages a successful cyber-attack can cause.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.