RSS文件输出(ASP.NET C#版)

StringBuilder sb = new StringBuilder();

            sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><?xml-stylesheet type=\"text/xsl\" href=\"/Styles/WebBarRss.xslt\"?>");

            sb.Append(System.Environment.NewLine);

            sb.Append("<rss version=\"2.0\">");

            sb.Append(System.Environment.NewLine);

            sb.Append("  <channel>");

            sb.Append(System.Environment.NewLine);

            sb.Append("    <title>" + title + "</title>");

            sb.Append(System.Environment.NewLine);

            sb.Append("    <link>http://www.###.com</link>");

            sb.Append(System.Environment.NewLine);

            sb.Append("    <description>" + title + "</description>");

            sb.Append(System.Environment.NewLine);

            WebBar.BLL.BArticle bArticle = new WebBar.BLL.BArticle();

            IList<ArticleEntity> ArticleEntitys = bArticle.List(int.Parse(ddlRssCount.SelectedValue.ToString()), int.Parse(ddlChannelID.SelectedValue.ToString()));

            foreach (ArticleEntity ae in ArticleEntitys)

            {

                sb.Append("    <item>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <title><![CDATA["+ae.ArticleTitle+"]]></title>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <link>http://www.###.com/Article/" + ae.ArticleID.ToString() + ".aspx</link>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <description><![CDATA["+ae.Description+"]]></description>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <author>"+ae.ArticleAuthor+"</author>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <pubDate>"+ae.ArticleCreateTime.ToString("yyyy-MM-dd HH:mm")+"</pubDate>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <comments>" + ae.CommentCount.ToString() + "</comments>");

                sb.Append(System.Environment.NewLine);

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

                sb.Append(System.Environment.NewLine);

            }

            sb.Append("  </channel>");

            sb.Append(System.Environment.NewLine);

            sb.Append("</rss>");

            try

            {

                using (FileStream fs = new FileStream(Server.MapPath(xmlFileName), FileMode.Create, FileAccess.Write, FileShare.Write))

                {

                    using (StreamWriter streamwriter = new StreamWriter(fs, Response.ContentEncoding))

                    {

                        streamwriter.Write(sb);

                        Common.JsUtility.Alert("成功生成RSS聚合内容");

                    }

                }

            }

当然:使用JSP,PHP和ASP的朋友也可以用此方法来尝试一下!具体代码我就不贴出来了!

转载于:https://www.cnblogs.com/200831856/archive/2009/10/12/create_rss.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值