[펌] 자바스크립트로 된 RSS 소스

자바스크립터 소스
/********************************************************
*RSS Reader Version 1.0
*Date: 2004/06/21
**********************************************************/

var xmldoc;
/**
*load rssfile
*@param URL : RSS URL
*/
function Load(URL) {
// Netscape
if (document.implementation && document.implementation.createDocument) {
xmldoc = document.implementation.createDocument(“”, “”, null);
xmldoc.onload = Create;
}else if (window.ActiveXObject) {         //IE
xmldoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmldoc.onreadystatechange = CheckState;
}
xmldoc.load(URL);
}

/*
*check xmldoc state
*only MSDOM
*/
function CheckState() {
var state = xmldoc.readyState;
if (state == 4) {
//end
document.write(Create());
}
}

/*
*parsing rss file
*/
function  Create() {

var channel = xmldoc.getElementsByTagName(“channel”);
// get channel title
var urlTitle = channel[0].childNodes[0].firstChild.nodeValue;
// get channel URL
var urlLink = channel[0].childNodes[1].firstChild.nodeValue;
var html = urlTitle +” “+ urlLink + “<hr size=1 noshade>”
var x = xmldoc.getElementsByTagName(‘item’);
for (i=0;i<x.length;i++)  {
for (j=0;j<x[i].childNodes.length;j++) {
if (x[0].childNodes[j].nodeType != 1) continue;
var nn = x[i].childNodes[j].nodeName;
var nv ;
if (nn == “title”)  {
nv = x[i].childNodes[j].firstChild.nodeValue;
var title  =  nv;
} else if (nn == “link”){
nv = x[i].childNodes[j].firstChild.nodeValue;
var link = nv;
// Support RSS1.0 & RSS2.0
} else if (nn == “date” || nn==”pubDate” || nn==”dc:date” ){
nv = x[i].childNodes[j].firstChild.nodeValue;
var date = nv;
} else {
continue;
}
}

html = html + “・<a href=”
+ link + ” target=_blank style=”padding-top:5px;padding-bottom:5px”>”
+ title + “</a> <i><font size=’1′ color=’#C2C2C2′>”
+ date + “</font></i><br>”;
}
return html+copyRight;
}

아래는 HTML 소스
———————————-
<html>
<head>
<title>kantianxia </title>
<script type=”text/javascript” src=”rssreader.js”></script>
</head>
<body>
<script>
Load(“http://www.kantianxia.com/rss/newsrss1.xml”)
</script>
</body>
</html>

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.