日期:2014-05-18  浏览次数:20506 次

100分求RSS技术
最近做了一个网站
经理让在实时信息页面上加上RSS功能
不知道有没有做过RSS的大哥
帮帮忙!
最好给小弟做一个简单的例子
(小弟以前没接触过RSS)

分不够可以再注册一个用户专门送分


------解决方案--------------------
可参考
,其中数据库连接部分可以自己替换
<%@ Page Language= "C# " AutoEventWireup= "true " %>

<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.Data.SqlClient " %>
<%@ Import Namespace= "System.Xml " %>
<%@ Import Namespace= "System.IO " %>

<script runat= "server ">
string HostUrl;
string HttpHead ;
string CateID;

protected void Page_Load( object sender, EventArgs e )
{
if(Request.QueryString[ "id "] == null)
{
Response.Write( " <error> error </error> ");
Response.End();
return;
}
CateID = Request.QueryString[ "id "].ToString();
int cateid = 0;
try
{
cateid = Convert.ToInt32(CateID);
}
catch(Exception xx)
{
Response.Write( " <error> no number </error> ");
Response.End();
return;
}

XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath( "reslib.config "));
string DataSource,UserID,Password;
XmlNode node = doc.SelectSingleNode( "/configuration/company/product[@name = 'reslib '] ");
if(node == null)
{
node = doc.SelectSingleNode( "/configuration/system ");
}

if(node == null)
{
Response.Write( " <error> no config node </error> ");
Response.End();
return;
}

DataSource = node.SelectSingleNode( "add[@key = 'DataSource ']/@value ").InnerText;
UserID = node.SelectSingleNode( "add[@key = 'UserID ']/@value ").InnerText;
Password = node.SelectSingleNode( "add[@key = 'Password ']/@value ").InnerText;
string ConnectionString = "Data Source= " + DataSource + ";Initial Catalog=reslib5;User Id= " + UserID + ";Password= " + Password + "; ";
SqlConnection cn = new SqlConnection(ConnectionString);
cn.Open();


HttpContext context = HttpContext.Current;
HostUrl = context.Request.Url.ToString();
HostUrl = HostUrl.Substring(0,HostUrl.IndexOf( "/ ",8));

XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, System.Text.Encoding.UTF8);
WriteRSSPrologue(writer);

WriteRSSHeadChennel(writer);

string sql= "select top 10 R_Title,R_Href,R_createdate From T_Resource ";
SqlCommand cmd = new SqlCommand(sql,cn);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DateTime dt;
while(dr.Read())
{
AddRSSItem(writer,(((DateTime)dr[ "R_createdate "]).ToUniversalTime()).ToString( "r "),dr[ "R_Title "].ToString(),HostUrl + dr[ "R_Href "].ToString());

}
dr.Close();
cn.Close();
cn = null;

writer.Flush();
writer.Close();

context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.ContentType = "text/xml ";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.End();

dr.Close();
cn.Dispose();
}

private XmlTextWriter Wri