前台:就一句话
<%@ Page Language="C#" CodeFile="rss.aspx.cs" Inherits="rss" %>
-----------------------------------------------------------------------------------------------------------------
后台代码:
string strRSS = "";
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/xml"; // 输出并按xml数据显示
Response.Write(GetRSS());
}
/// <summary>
/// 取得聚合文章
/// </summary>
public string GetRSS()
{
//DataSet ds = gr.GenerateRSS(); // 调用GenerateRSS()方法,获得数据
strRSS = strRSS + "<?xml version=/"1.0/" encoding=/"utf-8/" ?>";
strRSS = strRSS + "<?xml-stylesheet type=/"text/xsl/" href=/"rss.xsl/" media=/"screen/"?>";
strRSS = strRSS + "<rss version=/"2.0/">";
strRSS = strRSS + "<channel>";
strRSS = strRSS + "<title>学习社区</title>";
strRSS = strRSS + "<link>http://218.106.183.120/</link>";
strRSS = strRSS + "<copyright>Copyright (c) 学习社区</copyright>";
strRSS = strRSS + "<description>Latest 20 threads</description>";
strRSS = strRSS + "<generator>Discuz!NT</generator>";
strRSS = strRSS + "<pubDate>Fri, 27 Mar 2009 16:21:08 GMT</pubDate>";
strRSS = strRSS + "<ttl>60</ttl>";
using (scn = new SqlConnection())
{
scn.ConnectionString = "server=.;uid=sa;pwd=111111;database=pubs;";
scn.Open();
using (sda = new SqlDataAdapter())
{
sda.SelectCommand = scn.CreateCommand();
sda.SelectCommand.CommandText = "select * from jobs";
sda.SelectCommand.ExecuteNonQuery();
DataSet ds = new DataSet();
sda.Fill(ds);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
strRSS = strRSS + "<item>";
strRSS = strRSS + "<title>" + dr["job_desc"].ToString().Trim() + "</title>";
strRSS = strRSS + "<link>http://www.com-edu.cn</link> "; //标题链接
strRSS = strRSS + "<description><![CDATA[中华人民共和国]]></description>";
strRSS = strRSS + "<copyright>土人制造</copyright>";
strRSS = strRSS + "<pubDate>" + dr["min_lvl"].ToString().Trim() + "</pubDate>";
strRSS = strRSS + "<comments>http://www.com-edu.cn</comments>"; //注释链接
strRSS = strRSS + "</item>";
}
}
}
}
strRSS = strRSS + "</channel>";
strRSS = strRSS + "</rss>";
return strRSS;
}
rss2.0参考
/*<rss version="2.0">
<channel>
<title>学习社区</title>
<link>http://218.106.183.120/</link>
<description>Latest 20 threads</description>
<copyright>Copyright (c) 学习社区</copyright>
<generator>Discuz!NT</generator>
<pubDate>Fri, 27 Mar 2009 16:21:08 GMT</pubDate>
<ttl>60</ttl>
<item>
<title>关于北京市高等教育自学考试2009年7月考试报考工作安排的通知</title>
<description><![CDATA[ 2009年7月北京市高等教育自学考试将于7月3日至5日在西城区和延庆县举行。本次考试开考的专业为《商务管理》(专、本科)、《金融管理》(专、本科),具体考试课程和时间详见考试时间表(附件)。本期考试的新生注册和报考工作全部实行网上办理,网址为:(北京教育考试院—自考业务办理)。
一、注册、报考、缴费时间
2009年4月15日至25日,逾期不予办理。
]]></description>
<link>http://218.106.183.120/showtopic-6.aspx</link>
<category>社区公告</category>
<author>风中竹影</author>
<pubDate>Tue, 24 Mar 2009 09:35:00 GMT</pubDate>
</item>
</channel>
</rss>
*/