Software:
News ToolsReg Shops |
Retrieving RSS/Atom Feeds with the Google AJAX Feed APIUsing feeds to manage online news.Published Friday 7th September 2007 14:54 GMT Receiving an Atom FeedIn 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
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAAAAItAEL-H-
GuOHsDfD7MxmlhSpY8xpRlVNOvpHrXTaq4lZbJurjRQMBL0DtsRGauRDjwp6d-
ST2IgadQ"></script>
The previous
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
feed.load(function(result) { });
Next, add a <body><div id="feed"></div></body> Then, in the callback function obtain the
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
var entry = result.feed.entries[i];
var div = document.createElement("div"); div.appendChild(document.createTextNode(entry.title));
And finally, add the 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:
The entries’ titles in the Atom feed are displayed – see Figure 4:
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.
Track this type of story as a custom Atom/RSS feed or by email.
|
|
||||||||
Top 20 stories • All The Week’s Headlines • Archive • Search