asp.net C# 简单RSS阅读器
public void ProcessRSSItem(string rssURL)
{
//使用一个字符串rssURL作为它的参数。这个字符串包含了RSS的URL。它使用rssURL的值建立了一个WebRequest项
System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
//请求的响应将会被放到一个WebResponse对象里
System.Net.WebResponse myResponse = myRequest.GetResponse();
//这个WebResponse对象被用来建立一个流来取出XML的值
System.IO.Stream rssStream = myResponse.GetResponseStream();
//使用一个XmlDocument对象来存储流中的XML内容。XmlDocument对象用来调入XML的内容
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();
rssDoc.Load(rssStream);
//个项应该在rss/channel/里。使用XPath表达,一个项节点列表可以如下方式创建
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");
string title = "";
string link = "";
string description = "";
for (int i = 0; i < rssItems.Count; i++)
{
System.Xml.XmlNode rssDetail;
rssDetail = rssItems.Item(i).SelectSingleNode("title");
if (rssDetail != null)
{
title = rssDetail.InnerText;
}
else
{
title = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("link");
if (rssDetail != null)
{
link = rssDetail.InnerText;
}
else
{
link = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("description");
if (rssDetail != null)
{
description = rssDetail.InnerText;
}
else
{
description = "";
}
Response.Write("<p><b><a href='" + link + "' target='new'>" + title + "</a></b>" + description + "</p>");
}
}
//读取rss
protected void btnRead_Click(object sender, EventArgs e)
{
string rssURL = txtUrl.Text.Trim();
Literal1.Text = "<font size=5><b>Site: " + rssURL + "</b></font><Br />";
ProcessRSSItem(rssURL);
}
{
//使用一个字符串rssURL作为它的参数。这个字符串包含了RSS的URL。它使用rssURL的值建立了一个WebRequest项
System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
//请求的响应将会被放到一个WebResponse对象里
System.Net.WebResponse myResponse = myRequest.GetResponse();
//这个WebResponse对象被用来建立一个流来取出XML的值
System.IO.Stream rssStream = myResponse.GetResponseStream();
//使用一个XmlDocument对象来存储流中的XML内容。XmlDocument对象用来调入XML的内容
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();
rssDoc.Load(rssStream);
//个项应该在rss/channel/里。使用XPath表达,一个项节点列表可以如下方式创建
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");
string title = "";
string link = "";
string description = "";
for (int i = 0; i < rssItems.Count; i++)
{
System.Xml.XmlNode rssDetail;
rssDetail = rssItems.Item(i).SelectSingleNode("title");
if (rssDetail != null)
{
title = rssDetail.InnerText;
}
else
{
title = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("link");
if (rssDetail != null)
{
link = rssDetail.InnerText;
}
else
{
link = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("description");
if (rssDetail != null)
{
description = rssDetail.InnerText;
}
else
{
description = "";
}
Response.Write("<p><b><a href='" + link + "' target='new'>" + title + "</a></b>" + description + "</p>");
}
}
//读取rss
protected void btnRead_Click(object sender, EventArgs e)
{
string rssURL = txtUrl.Text.Trim();
Literal1.Text = "<font size=5><b>Site: " + rssURL + "</b></font><Br />";
ProcessRSSItem(rssURL);
}
from: http://www.cnblogs.com/liudao/archive/2007/06/01/767672.html