ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
asp.net 页面中生成 RSS 2.0 提要

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

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>



相关文章

相关软件