|
Project Information
Links
|
The Project consists of a small JavaScript Class that allows the retrieval of RSS feeds via a cross-domain proxy. The RSS feed is proxied through an external domain, that converts it into JSON. This JSON can then be received in local JavaScript via a normal <script> tag. The class currently uses the Appjet JSON proxy. The great advantage of this class, is that you do not need to create a proxy on your domain, in order to retrieve RSS feeds via JavaScript. You can use the default JSON proxy at Appjet, or create your own proxy that will serve multiple domains. See: http://www.bucabay.com/2009/web-development/rss-feeds-via-cross-domain-json-proxy/ Example UsageSimple Example: // create an instance of RSSClient
var client = new RSSClient();
// url of rss feed
var url = 'http://rss.news.yahoo.com/rss/topstories';
// retrieve RSS Feed
client.getRSS(url, function(xml) {
/**
* Here you would receive the RSS fees as an XML DOM Document passed as first parameter
* You would then use DOM methods to read the XML document
*/
}
Example with DOM methods to parse the received XML Document: // create an instance of RSSClient
var client = new RSSClient();
// make sure the RSSClient is loaded
client.onload(function() {
// url of rss feed
var url = 'http://rss.news.yahoo.com/rss/topstories';
// retrieve the rss feed
client.getRSS(url, function(xml) {
// retrieve the channel and title of the RSS feed
var channel = xml.getElementsByTagName('channel')[0];
var channel_title = channel.getElementsByTagName('title')[0].firstChild.nodeValue;
// retrieve the items
var items = channel.getElementsByTagName('item');
for (var i = 0; i < items.length; i++) {
// retrieve title, link, desc from the item
var title = items[i].getElementsByTagName('title')[0].firstChild.nodeValue;
var link = items[i].getElementsByTagName('link')[0].firstChild.nodeValue;
var description = items[i].getElementsByTagName('description')[0].firstChild.nodeValue;
// here you would add the items to the page...
}
})
});More samples are in the source. |