<%@ Page Language="C#" ContentType="application/xml" Debug="true" ResponseEncoding="utf-8" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <scrīpt language="C#" runat="server"> void Page_Load(Object src, EventArgs e){
SqlConnection myConnection = new SqlConnection();
try{
myConnection.ConnectionString="server=127.0.0.1;database=BBSDB;uid=sa;pwd=''";
myConnection.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "[dbo].[up_listTopic]";
SqlDataReader myDataReader = myCommand.ExecuteReader();
//-----------make head detail-----------------
StringBuilder xmlhead = new StringBuilder();
xmlhead.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
xmlhead.Append("<rss version=\"2.0\">\n");
xmlhead.Append("\t<channel>\n");
xmlhead.Append("\t\t<title>MyBBS RSS Channel</title>\n");
xmlhead.Append("\t\t<link>http://192.168.0.44/thebbs</link>\n");
xmlhead.Append("\t\t<language>zh-cn</language>\n");
xmlhead.Append("\t\t<docs>MyBBS RSS Center</docs>\n");
xmlhead.Append("\t\t<descrīption>Latest 20 threads of all forums</descrīption>\n");
xmlhead.Append("\t\t<copyright>Copyright(C) MyBBS</copyright>\n");
xmlhead.Append("\t\t<generator>none</generator>\n");
xmlhead.Append("\t\t<lastBuildDate>" + DateTime.Now + "</lastBuildDate>\n");
xmlhead.Append("\t\t<ttl>90</ttl>\n");
xmlhead.Append("\t\t<image>\n");
xmlhead.Append("\t\t\t<url>http://127.0.0.1/thebbs/smile.gif</url>\n");
xmlhead.Append("\t\t\t<title>MyBBS</title>\n");
xmlhead.Append("\t\t\t<link>http://127.0.0.1/thebbs</link>\n");
xmlhead.Append("\t\t</image>\n");
//-----------make item-----------------
StringBuilder xmlitem = new StringBuilder();
string descrīption = "";
int i, num;
num = 1;
while(myDataReader.Read()){
//-----------read 20 record-----------------
if (num > 20) break;
num++;
descrīption = myDataReader[2].ToString();
if (descrīption.Length < 300)
i = descrīption.Length;
else
i = 300;
descrīption = descrīption.Substring(0, i);
xmlitem.Append("\t\t<item>\n");
xmlitem.Append("\t\t\t<title>" + myDataReader[1].ToString() + "</title>\n");
xmlitem.Append("\t\t\t<link>http://127.0.0.1/thebbs/topic.aspx?Tid=" + myDataReader[0].ToString() + "</link>\n");
xmlitem.Append("\t\t\t<descrīption><![CDATA[" + descrīption + "]]></descrīption>\n");
xmlitem.Append("\t\t\t<category>none</category>\n");
xmlitem.Append("\t\t\t<author>" + myDataReader[5].ToString() + "</author>\n");
xmlitem.Append("\t\t\t<pubDate>" + myDataReader[4].ToString() + "</pubDate>\n");
xmlitem.Append("\t\t</item>\n");
}
myConnection.Close();
//-----------make footer-----------------
StringBuilder xmlfooter = new StringBuilder();
xmlfooter.Append("\t</channel>\n</rss>");
//-----------Output Data-----------------
Response.Write(xmlhead);
Response.Write(xmlitem);
Response.Write(xmlfooter);
}catch(Exception ex){
//-----------can not find DB process-----------------
Response.Write("<ErrorMsg>Connection Database Error...</ErrorMsg>");
}
}
</scrīpt> 配好路径后用浏览器Go IE6.0的话没有继承RSS阅读只显示XML的结构..... OK就这样写完老
P.S. 编辑器会自动替换掉一些字符 如:<scrīpt>中的 i ==> ī