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 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
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:
Next, we shall display multiple feeds using the <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 var feedControl = new google.feeds.FeedControl(); Specify the Atom Feeds to be loaded by the
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
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:
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. ®
Track this type of story as a custom Atom/RSS feed or by email.
|
|
||||||||
Top 20 stories • All The Week’s Headlines • Archive • Search