生成RSS

 

代码
private void DataLoad()
        {
            BLLContents bllContents 
= new BLLContents();
            List
<MODContents> mods = bllContents.GetDataMod("");

            ProLight.CMS.MyRss myRSS 
= new ProLight.CMS.MyRss();
            
string rssData = myRSS.CreateRSS();

            Response.Charset 
= "UTF-8";
            Response.ContentType 
= "Application/xml";
            Response.ContentEncoding 
= System.Text.Encoding.UTF8;
            Response.Write(rssData);
            Response.Flush();
            Response.End();
        }

public  class MyRss
    {
        
public String CreateRSS()
        {
            StringBuilder sb 
= new StringBuilder();

            BLLContents bllContents 
= new BLLContents();
            List
<MODContents> mods = bllContents.GetDataMod("");

            
//添加文件头。
            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine(
"<rss xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance/" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema/" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash//" version=\"2.0\">");
            sb.AppendLine("<channel>");
            sb.AppendLine(
"<title>我的RSS-管理递归月</title>");
            sb.AppendLine(
"<link>http://localhost:1442/</link>");
            sb.AppendLine(
"<description>描述信息</description><language>zh-CN</language><generator>www.firstniu.com</generator><copyright>北京风讯公司</copyright>");
            
foreach (MODContents mod in mods)
            {
                sb.AppendLine(
"<item>");
                sb.AppendLine(
"<title>" + mod.Caption + "</title>");
                sb.AppendLine(
"<link>http://localhost:1442/news.aspx?id=" + mod.id + "</link>");
                sb.AppendLine(
"<author>" + mod.Author + "</author>");
                sb.AppendLine(
"<guid>" + mod.id + "</guid>");
                sb.AppendLine(
"<pubDate>" + mod.Created + "</pubDate>");
                sb.AppendLine(
"<comments>" + mod.Actor + "</comments>");
                sb.AppendLine(
"<slash:comments>" + mod.ViewCount + "</slash:comments>");
                sb.AppendLine(
"<source url=\"http://localhost:1442/news.aspx?id=" + mod.id + "\">" + mod.Caption + "</source>");

                
string contents = ProLight.CMS.PubConfig.NoHTML(mod.Contents);
                
if (contents.Length > 300)
                {
                    contents 
= contents.Substring(0298+ "...";
                }
                sb.AppendLine(
"<description><![CDATA[" + contents + "]]></description>");

                sb.AppendLine(
"</item>");

            }

            sb.AppendLine(
"</channel>");
            sb.AppendLine(
"</rss>");
            
return sb.ToString();
        } 
    }
posted @ 2010-07-16 17:57  凭栏处  阅读(751)  评论(0编辑  收藏  举报