转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
asp.net 页面中生成 RSS 2.0 提要         ★★★★

asp.net 页面中生成 RSS 2.0 提要

作者:闵涛 文章来源:闵涛的学习笔记 点击数:889 更新时间:2009/4/23 10:43:01

Figure 1 Sample RSS 1.0 Document

<rdf:RDF 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns="http://purl.org/rss/1.0/"
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
>
  <channel rdf:about="http://skonnard.com/blog/rss.xml">
    <title>The XML Files</title>
    <link>http://skonnard.com/blog</link>
    <description>by Aaron Skonnard</description>
    <image rdf:resource="http://skonnard.com/blog/images/image.gif" />
    <items>
      <rdf:Seq>
        <rdf:li resource=" http://skonnard.com/blog/entry1" />
        <rdf:li resource=" http://skonnard.com/blog/entry2" />
      </rdf:Seq>
    </items>
  </channel> 
  <image rdf:about=" http://skonnard.com/blog/images/image.gif">
    <title>skonnard.com</title>
    <link>http://skonnard.com/blog</link>
    <url>http://skonnard.com/blog/images/image.gif</url>
  </image>
  <item rdf:about="http://skonnard.com/blog/entry1">
    <title>1st blog entry</title>
    <link>http://skonnard.com/blog/entry1</link>
    <description>This is my first blog entry.</description>
    <dc:date>2004-01-13T17:16:44.9803903-07:00</dc:date>
  </item>
  <item rdf:about="http://skonnard.com/blog/entry1">
    <title>2nd Blog Entry</title>
    <link>http://skonnard.com/blog/entry1</link>
    <description>This is my second blog entry.</description>
    <dc:date>2004-01-13T17:16:45.9803903-07:00</dc:date>
  </item>
</rdf:RDF>

Figure 2 Sample RSS 2.0 Document
<rss version="2.0">
  <channel>
    <title>The XML Files</title>
    <link>http://Skonnard.com/blog</link>
    <description>by Aaron Skonnard</description>
    <image>
      <url>http://skonnard.com/blog/images/image.gif</url>
      <title>skonnard.com</title>
      <link>http://skonnard.com/blog/</link>
    </image>
    <item>          
      <title>1st blog entry</title>
      <link>http://skonnard.com/blog/entry1</link>
      <description>This is my first blog entry.</description>
      <pubDate>Wed, 14 Jan 2004 17:16:44 GMT</pubDate>
    </item>
    <item>
      <title>2nd blog entry</title>
      <link>http://skonnard.com/blog/entry1</link>
      <description>This is my second blog entry</description>
      <pubDate>Wed, 14 Jan 2004 17:16:45 GMT</pubDate>
    </item>
  </channel>
</rss>

Figure 3 Sample Atom 0.3 Feed
<feed version="0.3" xml:lang="en-us" 
  xmlns="http://purl.org/atom/ns#"
>
  <title>The XML Files</title>
  <link>http://skonnard.com/blog/</link>
  <modified>2004-01-13T17:16:45.0004199-07:00</modified>
  <tagline>by Aaron Skonnard</tagline>
  <author>
    <name>Aaron Skonnard</name>
  </author>
  <entry>
    <title>1st blog entry</title>
    <link>http://skonnard.com/blog/entry1</link>
    <created>2004-01-13T17:16:44.9803903-07:00</created>
    <content type="text/html" mode="xml">
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This is my first blog entry</p>
      </body>
    </content>
  </entry>
  <entry>
    <title>2nd blog entry</title>
    <link>http://skonnard.com/blog/entry2</link>
    <created>2004-01-13T17:16:45.9803903-07:00</created>
    <content type="text/html" mode="xml">
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This is my second blog entry</p>
      </body>
    </content>
  </entry>
</feed>

Figure 4 Sample Blogroll (OPML)
<opml>
  <head> <title>Aaron''''s Favorite Blogs</title> </head>
  <body>
    <outline type="rss" title="PDC Bloggers" 
      description="PDC Bloggers website" 
      xmlUrl="http://pdcbloggers.net/Feed.rss" 
      htmlUrl="http://PDCBloggers.net" />
    <outline type="rss" title="MSDN Magazine: Current Issue" 
      description="The Microsoft Journal for Developers" 
      xmlUrl="http://msdn.microsoft.com/msdnmag/rss/recent.xml" 
      htmlUrl="http://msdn.microsoft.com/msdnmag/" />
    <outline type="rss" title="MSDN Just Published" 
      description="Keep current ..." 
      xmlUrl="http://msdn.microsoft.com/rss.xml"  
      htmlUrl="http://msdn.microsoft.com/" />    
  </body>
</opml>

Figure 5 Generating an RSS 2.0 Feed in ASP.NET
<%@ Page language="c#" Codebehind="rss.aspx.cs" 
    AutoEventWireup="false" Inherits="SimpleBlog.rss" %>
<rss version="2.0">
  <channel>
    <title>My Blog</title>        
    <link>http://localhost/simpleblog/default.aspx</link>
    <description>A weblog about nothing...</description>
    <language>en-us</language>
    <asp:Repeater id="Items" runat="server">
      <ItemTemplate>
        <item>
        <title><%#DataBinder.Eval(Container.DataItem,
            "title")%></title>
        <description><%#DataBinder.Eval(
            Container.DataItem,"description")%></description>
        <pubDate><%#DataBinder.Eval(Container.DataItem, 
            "pubdate") %></pubDate>
        <link><%# DataBinder.Eval(Container.DataItem, "link") %></link>
        </item>
      </ItemTemplate>
    </asp:Repeater>
  </channel>
</rss>

Figure 6 RSS Aggregator Web User Control
<%@ Control Language="c#" AutoEventWireup="true" 
    EnableViewState="false" Debug="true"%>
<%@ Import namespace="System.Xml" %>
<%@ OutputCache Duration="1800" VaryByParam="none" %>
<script runat="server" language="C#">
private void Page_Load(object sender, System.EventArgs e)
{
  StringBuilder sb = new StringBuilder();
  XmlDocument doc = new XmlDocument();
  doc.Load(Server.MapPath("blogroll.opml"));
  int numToDisp = int.Parse(doc.SelectSingleNode(
    "/opml/@numberToDisplay").InnerText);
  XmlNodeList rss = doc.SelectNodes("//outline/@xmlUrl");
  foreach (XmlNode r in rss)
  {
    XmlDocument blogdoc = new XmlDocument();
    blogdoc.Load(r.Value);
    XmlNodeList items = blogdoc.SelectNodes("//item");  
    for (int i=0; i<items.Count && i<numToDisp; i++)
    {
      string author="";
      XmlNode authorNode = items[i].SelectSingleNode(
       "*[local-name()=''''author'''' or local-name()=''''creator'''']");
      if (authorNode != null) author = authorNode.InnerText;
      sb.Append(String.Format(
        "&#149;&nbsp;<a href={0}>{1} ({2})</a><br/>",
        items[i].SelectSingleNode("link").InnerText,
        items[i].SelectSingleNode("title").InnerText, author));
    }        
  }
  EntriesHTML.Text = sb.ToString();
}
</script>
<style> <!-- styles omitted for brevity --> ...  </style>

<div class="title">UNUG Blogs</div>
<asp:Literal id="EntriesHTML" runat="server"></asp:Literal>


[聊天工具]动画教程:学用Foxmail 6.0的RSS功能__天极Yesky  [聊天工具]Foxmail 6.0 Beta1发布!加入RSS阅读器
[聊天工具]MSN群V2.0Beta1发布 不安装MSN群也能群聊__天极Ye…  [常用软件]bcastr2.0 通用的图片浏览器
[常用软件]最终功能完成:Firefox 2.0 RC1推出  [常用软件]省事省心,看我BT、RSS双剑合璧
[常用软件]IE7 Build 5299 RSS新功能抢先看  [VB.NET程序]用VB.NET写的一个简易的RSS阅读器
[Delphi程序]RSS 与 blog 阅读器:什么是 RSS 与 Atom ?  [Delphi程序]Delphi的RSS开源项目正式启动了!
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台