Hi Folks,
Place the following code in an external javascript file:
================================================
/* Function Used to Display Months in Words as Jan, Feb...*/
function WordMonth(intMonth){
var MonthArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
return MonthArray[intMonth]
}
/*Function Used to Fetch RSS Feeds from Other websites to yours...It
works with BoDY ONLOAD Functionality!*/
function GetRSSNews(){
/*First*/
/*You can set as much as you want to display Feeds*/
var iMax = 20
/*ActiveX Object Initialization*/
var rssDoc = new ActiveXObject("Microsoft.XMLDOM")
rssDoc.async = false
/*Insert your Required URL to be fetched>>For a Ref, I have used BBC
Feed*/
rssDoc.load("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/
front_page/rss.xml")
/*You can assume it as DOM Structure of a XML Document for Logical
Means*/
var headNode = rssDoc.selectNodes("/rss/channel")
var itemNodes = rssDoc.selectNodes("/rss/channel/item")
/*Condition to check if Length of item Nodes is greater or lesser
than the Parameter used to get no. of items displayed*/
if(itemNodes.length<iMax){
iMax = itemNodes.length
}
/*Variable Initialization for FEEDBODY*/
var feedBody = ""
/*For Loop Initialization to incoporate iMax Parameter for getting
Various items in display*/
for(i=0;i<iMax;i++){
var pubDate = new Date(itemNodes.item(i).getElementsByTagName
("pubDate").item(0).text)
/*alert(pubDate+"-"+pubDate.getDate()+"/"+(pubDate.getMonth()
+1)+"/"+pubDate.getFullYear())*/
var tempPubDate = pubDate.getDate()+ " " + WordMonth
(pubDate.getMonth())+ " " +pubDate.getFullYear()
feedBody = feedBody + tempPubDate + " <a style='text-transform:
lowercase;' class='article' target='_blank' href='" +
itemNodes.item (i).getElementsByTagName("link").item(0).text + "'>" +
itemNodes.item(i).getElementsByTagName("title").item
(0).text +"</a><br /><br />"
}
myFeeds.innerHTML = feedBody
}
================================================
Place the following code in HTML file:
================================================
<html>
<head>
<title>RSS Feeds Test</title>
</head>
<body class="mainBody" onload="GetRSSNews();">
<div id="myFeeds" style="padding: 0px 8px 0px 8px;"><script src="js/
rss/rss.js"></script></div>
</body>
================================================
Please make sure that who ever using my code is changing the
Javascript location path as per their need.
Hope this works out for all those having problems in fetching RSS
Feeds using JavaScript!
Cheers,
Ayusman,
CSC
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---