<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>this is test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function XHConn()
{
var xmlhttp, bComplete = false;
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if (!xmlhttp) return null;
this.connect = function(sURL, sMethod, sVars, fnDone)
{
if (!xmlhttp) return false;
bComplete = false;
sMethod = sMethod.toUpperCase();
try {
if (sMethod == "GET")
{
xmlhttp.open(sMethod, sURL+ ((sURL.indexOf("?")==-1)? "?":"&") +sVars, true);
sVars = "";
}
else
{
xmlhttp.open(sMethod, sURL, true);
xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && !bComplete)
{
bComplete = true;
fnDone(xmlhttp);
}};
xmlhttp.send(sVars);
}
catch(z) { return false; }
return true;
};
return this;
}
function readRSS(url) {
var myConn = new XHConn();
if (!myConn) {alert("error");return;}
myConn.connect(url, "GET", "", ResultSet);
}
var ResultSet = function(obj)
{
var results = obj.responseXML;
var title = null;
var item = null;
var link=null;
var author=null;
var pubDate=null;
var description=null;
//得到channel
var headtitle=results.selectSingleNode("rss/channel/title").text;
var headlink=results.selectSingleNode("rss/channel/link").text;
var cell = document.createElement("div");
cell.innerHTML="<h1><a href="+headlink+" target=_blank>"+headtitle+"</a></h1><br/>";
document.getElementById("result").appendChild(cell);
//得到items
var items = results.selectNodes("rss/channel/item");
for(var i = 0; i < items.length; i++) {
item = items[i];
link=item.getElementsByTagName("link")[0].firstChild.nodeValue;
title = item.getElementsByTagName("title")[0].firstChild.nodeValue;
pubDate= item.getElementsByTagName("pubDate")[0].firstChild.nodeValue;
author= item.getElementsByTagName("dc:creator")[0].firstChild.nodeValue;
// description=item.getElementsByTagName("description")[0].firstChild.nodeValue;
var cell = document.createElement("div");
cell.innerHTML="<a href="+link+" target=_blank>"+title+"</a><font color=red>     作者:</font>"+author+"<br/>";
document.getElementById("result").appendChild(cell);
//var cell1=document.createElement("div");
//cell1.innerHTML=description;
// document.getElementById("result").appendChild(cell1);
}
}
function readrss1()
{
readRSS("http://blog.csdn.net/wl076/Rss.aspx");
}
window.onload = readrss1;
</script>
</head>
<body>
<form>
<div id="result"></div>
</form>
</body>
</html>
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1587440
联系客服