程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#+ASP.NET開發基於Web的RSS閱讀器(2)

C#+ASP.NET開發基於Web的RSS閱讀器(2)

編輯:關於C語言

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHtml 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xHtml1-transitional.dtd">
<script runat="server">
public void ProcessRSSItem(string rssURL)
{
 System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
 System.Net.WebResponse myResponse = myRequest.GetResponse();
 System.IO.Stream rssStream = myResponse.GetResponseStream();
 System.Xml.XmlDocument rssDoc = new System.Xml.XMLDocument();
 rssDoc.Load(rssStream);
 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><br/>");
  Response.Write(description + "</p>");
 }
}
</script>
<html XMLns="http://www.w3.org/1999/xHtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%
 string rssURL = "http://www.codeguru.com/icom_includes/feeds/codeguru/rss-all.XML";
 Response.Write("<font size=5><b>Site: " + rssURL + "</b></font><Br />");
 ProcessRSSItem(rssURL);
 Response.Write("<hr />");
 rssURL = "http://www.developer.com/icom_includes/feeds/special/dev-5.XML";
 Response.Write("<font size=5><b>Site: " + rssURL + "</b></font><Br />");
 ProcessRSSItem(rssURL);
%>
</div>
</form>
</body>
</Html>

顯示結果如下:

-
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved