RSS功能制作

本文通过一个RSS2.0示例文件详细解析了RSS2.0规范中的名称空间使用方法及其XML结构,包括频道信息、条目详情等,并提供了一个使用ASP.NET创建RSS2.0文件的具体实现。

RSS 2.0 规范示例文件中的名称空间

<?xml version="1.0"?>

<!-- RSS generated by Radio UserLand v8.0.5 on 9/30/2002; 4:00:00 AM Pacific -->

<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">

 <channel>

   <title>Scripting News</title>

   <link>http://www.scripting.com/</link>

   <description>A weblog about scripting and stuff like that.</description>

   <language>en-us</language>

   <blogChannel:blogRoll>

     http://radio.weblogs.com/0001015/userland/scriptingNewsLeftLinks.opml

   </blogChannel:blogRoll>

     <item>

     <description>Joshua Allen:

     <a href="http://www.netcrucible.com/blog/2002/09/29.html#a243">

     Who loves namespaces?</a></description>

     <pubDate>Sun, 29 Sep 2002 19:59:01 GMT</pubDate>

     <guid>

     http://scriptingnews.userland.com/backissues/2002/09/29#When:12:59:01PM

     </guid>

     </item>

 </channel>

</rss>

----------------------------
ASP.NET代码:(注:应该注意时间的问题)
 XElement rss = new XElement("rss");
                rss.SetAttributeValue("version", "2.0");
                XElement channel = new XElement("channel", new XElement[]{  
                new XElement("title","尹萧风论坛"),  
                new XElement("link","http://yinxiaofeng.net"),  
                new XElement("description","尹萧风论坛的最新帖子发布情况"),  
            });
                for (int i = 1; i < 6; i++)
                {
                    XElement item = new XElement("item", new XElement[] {
                       new XElement("title","帖子"+i),  
                       new XElement("link","http://localhost:15108/"),  
                       new XElement("description","帖子内容"),
                       new XElement("pubDate",DateTime.UtcNow.ToString("r"))
                   
                    });
                    channel.Add(item);
                }
                rss.Add(channel);
                Response.Write(rss.ToString());
                Response.End();

转载于:https://www.cnblogs.com/yinxiaofeng/archive/2012/08/02/2619668.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值