比如,一个典型的RSS烧制过程是:用户提交RSS地址到服务器,服务器接受请求,记录RSS地址,负责索引数据的服务器索引指定地址的数据,将数据写到数据库中,在用户请求时将数据呈现...
这是笔者比较浅显的理解,请批评...
-- ReadRss.aspx
<%@ Page language="c#" Codebehind="ReadRSS.aspx.cs" AutoEventWireup="false" Inherits="Manager.ReadRSS" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>RSS阅读器</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P style="FONT-SIZE: 11px">Feed种子:
<asp:TextBox id="FeedUrl" runat="server"></asp:TextBox><BR>
显示条数:
<asp:TextBox id="Num" runat="server" Width="48px"></asp:TextBox></P>
<P style="FONT-SIZE: 11px">
<asp:Button id="GetFeed" runat="server" Text="获得RSS"></asp:Button><BR>
<BR>
<asp:Label id="RssFeed" runat="server"></asp:Label></P>
</form>
</body>
</HTML>
-- ReadRss.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Xml;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Manager
{
/// <summary>
/// RSS在线阅读工具
/// </summary>
public class ReadRSS : System.Web.UI.Page
{
private string strRssList = "";
private XmlNodeList objItems;
private XmlNodeList objItemsChild;
private int i;
private string title;
protected System.Web.UI.WebControls.Label RssFeed;
protected System.Web.UI.WebControls.Button GetFeed;
protected System.Web.UI.WebControls.TextBox FeedUrl;
protected System.Web.UI.WebControls.TextBox Num;
private string url;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{}
}
/// <summary>
/// 获得要显示的Feed种子数据
/// </summary>
/// <param name="RssUrl"></param>
/// <param name="showNewsCount"></param>
/// <returns></returns>
public string LoadRSS(string RssUrl, int showNewsCount)
{
string str;
try
{
XmlDocument objXMLDoc = new XmlDocument();
objXMLDoc.Load(RssUrl);
objItems = objXMLDoc.GetElementsByTagName("item");
if(RssUrl == "")
{
str = "未找到信息源,您可刷新重试或联系管理员!";
}
if(showNewsCount.ToString() == "" || showNewsCount > 30)
showNewsCount = 10;
if(showNewsCount == 0)
showNewsCount = objItems.Count;
if(objXMLDoc.HasChildNodes == true)
{
i = 1;
foreach(XmlNode objNode in objItems)
{
if(i<=showNewsCount)
{
if(objNode.HasChildNodes == true)
{
objItemsChild = objNode.ChildNodes;
foreach(XmlNode objNodeChild in objItemsChild)
{
if(objNodeChild.Name=="title")
{
title = objNodeChild.InnerText;
}
if(objNodeChild.Name=="link")
{
url = objNodeChild.InnerText;
}
}
i = i+1;
strRssList += "<a href=" + url +" target=_blank>" + title + "</a><br>";
}
}
}
}
str = strRssList;
}
catch
{
str = "RSS Feed 源数据出错!";
}
return str;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.GetFeed.Click += new System.EventHandler(this.GetFeed_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
/// <summary>
/// 获得Feed种子
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GetFeed_Click(object sender, System.EventArgs e)
{
RssFeed.Text = LoadRSS(FeedUrl.Text,Convert.ToInt32(Num.Text));
}
}
}