Wed Aug 22, 2012 2:21 pm
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Feeds Title</title>
<description>Feeds by RSS example</description>
<link>http://www.codemiles.com/rss.html</link>
<lastBuildDate>Mon, 06 Sep 2012 00:02:00 +0000 </lastBuildDate>
<pubDate>Mon, 06 Sep 2012 11:13:00 +0000 </pubDate>
<ttl>1800</ttl>
<item>
<title>RSS feeds parsing</title>
<description>How to parse RSS in javascript....</description>
<link>http://www.codemiles.com/javascriptRSS.html</link>
<guid>unique string per item</guid>
<pubDate>Mon, 06 Sep 2012 11:11:00 +0000 </pubDate>
</item>
</channel>
</rss>
<script type="text/javascript">
dojo.addOnLoad(function() {
var divID = "divShow";
// Parse Rss Feed
dojo.xhrGet({
url: "rssFile.xml",
preventCache: true,
handleAs: "xml",
load: function(xmlDoc, ioArgs){
var i = 0;
var htmlReturn = "";
var mainNode = xmlDoc.getElementsByTagName("channel").item(0);
if (mainNode == null) {
console.debug("Error in RSS format ...");
return;
}
var NumberOfItems = mainNode.getElementsByTagName("item").length;
for (i = 0; i < NumberOfItems; ++i) {
var entry = mainNode.getElementsByTagName('item').item(i);
var title = entry.getElementsByTagName('title').item(0).firstChild.data;
var published = entry.getElementsByTagName('pubDate').item(0).firstChild.data;
var description = entry.getElementsByTagName('description').item(0).firstChild.data;
var link = entry.getElementsByTagName('link').item(0).firstChild.data;
htmlReturn += '<hr><p><a target="_blank" href="' + link +'">' + title + '</a><br/>' +
'<span class="smaller">' + published + '</span><br/>' +
description +
'</p>';
}
document.getElementById(divID).innerHTML = htmlReturn;
},
error: function(error, ioArgs){
dojo.byId(divID).innerHTML = "Failed To Load RSS Feeds";
console.debug("failed xhrGet for Rss URL: ", error, ioArgs);
}
});
});
</script>
<div id="divShow"></div>
http://en.wikipedia.org/wiki/RSS
http://en.wikipedia.org/wiki/Dojo_Toolkit
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.