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( "• <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>
本文地址:http://com.8s8s.com/it/it7284.htm