跟小D每日学口语

生成RSS

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.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class RSS : System.Web.UI.Page {   
    string strRSS = "";

    protected void Page_Load(object sender, System.EventArgs e) {
        Response.ContentType = "application/xml"; // 输出并按xml数据显示
        Response.Write(GetRSS());
        Response.End();
    }

    /// <summary>
    /// 取得聚合文章
    /// </summary>
    public string GetRSS() {
        strRSS = strRSS + "<rss version=\"2.0\">";
        strRSS = strRSS + "<channel>";
        strRSS = strRSS + "<title>title</title>";
        strRSS = strRSS + "<link>http://www.microsoft.com</link>";
        strRSS = strRSS + "<description>just a testing</description>";
        for (int i = 0; i < 10; i++) {
            strRSS = strRSS + "<item>";
            strRSS = strRSS + "<title><![CDATA[Title:" + i.ToString() + "]]></title>";
            strRSS = strRSS + "<link>http://cnblogs.com/javak" + "</link> ";
            strRSS = strRSS + "<description><![CDATA[" + i.ToString() + "]]></description>";
            strRSS = strRSS + "<copyright>free copy</copyright>";
            strRSS = strRSS + "<pubDate>" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "</pubDate>";
            strRSS = strRSS + "<comments>http://cnblogs.com/javak</comments>";
            strRSS = strRSS + "</item>";
        }
        strRSS = strRSS + "</channel>";
        strRSS = strRSS + "</rss>";

        return strRSS;
    }

    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e) {
        //
        // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent() {
        this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
}

posted @ 2009-01-13 16:24  javak  阅读(346)  评论(2编辑  收藏  举报