Feeds

Retrieving RSS/Atom Feeds with the Google AJAX Feed API

Using feeds to manage online news.

Internet Security Threat Report 2014

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.

Security for virtualized datacentres

More from The Register

next story
Microsoft WINDOWS 10: Seven ATE Nine. Or Eight did really
Windows NEIN skipped, tech preview due out on Wednesday
Business is back, baby! Hasta la VISTA, Win 8... Oh, yeah, Windows 9
Forget touchscreen millennials, Microsoft goes for mouse crowd
Apple: SO sorry for the iOS 8.0.1 UPDATE BUNGLE HORROR
Apple kills 'upgrade'. Hey, Microsoft. You sure you want to be like these guys?
ARM gives Internet of Things a piece of its mind – the Cortex-M7
32-bit core packs some DSP for VIP IoT CPU LOL
Microsoft on the Threshold of a new name for Windows next week
Rebranded OS reportedly set to be flung open by Redmond
Lotus Notes inventor Ozzie invents app to talk to people on your phone
Imagine that. Startup floats with voice collab app for Win iPhone
'Google is NOT the gatekeeper to the web, as some claim'
Plus: 'Pretty sure iOS 8.0.2 will just turn the iPhone into a fax machine'
SMASH the Bash bug! Apple and Red Hat scramble for patch batches
'Applying multiple security updates is extremely difficult'
prev story

Whitepapers

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.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
The next step in data security
With recent increased privacy concerns and computers becoming more powerful, the chance of hackers being able to crack smaller-sized RSA keys increases.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.