﻿{"id":1599,"date":"2011-05-23T22:06:36","date_gmt":"2011-05-23T14:06:36","guid":{"rendered":"http:\/\/blog.jixin.ntxz.net\/?p=1599"},"modified":"2011-05-23T22:06:36","modified_gmt":"2011-05-23T14:06:36","slug":"asp-net-%e9%a1%b5%e9%9d%a2%e4%b8%ad%e7%94%9f%e6%88%90-rss-2-0","status":"publish","type":"post","link":"http:\/\/www.ntxz.net\/?p=1599","title":{"rendered":"asp.net \u9875\u9762\u4e2d\u751f\u6210 RSS 2.0"},"content":{"rendered":"<p>Figure 1 Sample RSS 1.0 Document<\/p>\n<p><rdf:RDF \n  xmlns:rdf=\"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#\"\n  xmlns=\"http:\/\/purl.org\/rss\/1.0\/\"\n  xmlns:dc=\"http:\/\/purl.org\/dc\/elements\/1.1\/\" \n><br \/>\n  <channel rdf:about=\"http:\/\/skonnard.com\/blog\/rss.xml\"><br \/>\n    <title>The XML Files<\/title>\n    <link>http:\/\/skonnard.com\/blog<\/link>\n    <description>by Aaron Skonnard<\/description><br \/>\n    <image rdf:resource=\"http:\/\/skonnard.com\/blog\/images\/image.gif\" \/><br \/>\n    <items><br \/>\n      <rdf:Seq><br \/>\n        <rdf:li resource=\" http:\/\/skonnard.com\/blog\/entry1\" \/><br \/>\n        <rdf:li resource=\" http:\/\/skonnard.com\/blog\/entry2\" \/><br \/>\n      <\/rdf:Seq><br \/>\n    <\/items><br \/>\n  <\/channel><br \/>\n  <image rdf:about=\" http:\/\/skonnard.com\/blog\/images\/image.gif\"><br \/>\n    <title>skonnard.com<\/title>\n    <link>http:\/\/skonnard.com\/blog<\/link>\n    <url>http:\/\/skonnard.com\/blog\/images\/image.gif<\/url><br \/>\n  <\/image><br \/>\n  <item rdf:about=\"http:\/\/skonnard.com\/blog\/entry1\"><br \/>\n    <title>1st blog entry<\/title>\n    <link>http:\/\/skonnard.com\/blog\/entry1<\/link>\n    <description>This is my first blog entry.<\/description><br \/>\n    <dc:date>2004-01-13T17:16:44.9803903-07:00<\/dc:date><br \/>\n  <\/item><br \/>\n  <item rdf:about=\"http:\/\/skonnard.com\/blog\/entry1\"><br \/>\n    <title>2nd Blog Entry<\/title>\n    <link>http:\/\/skonnard.com\/blog\/entry1<\/link>\n    <description>This is my second blog entry.<\/description><br \/>\n    <dc:date>2004-01-13T17:16:45.9803903-07:00<\/dc:date><br \/>\n  <\/item><br \/>\n<\/rdf:RDF><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nFigure 2 Sample RSS 2.0 Document<\/p>\n<p><rss version=\"2.0\"><br \/>\n  <channel><br \/>\n    <title>The XML Files<\/title>\n    <link>http:\/\/Skonnard.com\/blog<\/link>\n    <description>by Aaron Skonnard<\/description><br \/>\n    <image><br \/>\n      <url>http:\/\/skonnard.com\/blog\/images\/image.gif<\/url><br \/>\n      <title>skonnard.com<\/title>\n      <link>http:\/\/skonnard.com\/blog\/<\/link>\n    <\/image><br \/>\n    <item><br \/>\n      <title>1st blog entry<\/title>\n      <link>http:\/\/skonnard.com\/blog\/entry1<\/link>\n      <description>This is my first blog entry.<\/description>\n      <pubDate>Wed, 14 Jan 2004 17:16:44 GMT<\/pubDate>\n    <\/item><br \/>\n    <item><br \/>\n      <title>2nd blog entry<\/title>\n      <link>http:\/\/skonnard.com\/blog\/entry1<\/link>\n      <description>This is my second blog entry<\/description>\n      <pubDate>Wed, 14 Jan 2004 17:16:45 GMT<\/pubDate>\n    <\/item><br \/>\n  <\/channel><br \/>\n<\/rss><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nFigure 3 Sample Atom 0.3 Feed<\/p>\n<p><feed version=\"0.3\" xml:lang=\"en-us\" \n  xmlns=\"http:\/\/purl.org\/atom\/ns#\"\n><br \/>\n  <title>The XML Files<\/title>\n  <link>http:\/\/skonnard.com\/blog\/<\/link>\n  <modified>2004-01-13T17:16:45.0004199-07:00<\/modified><br \/>\n  <tagline>by Aaron Skonnard<\/tagline><br \/>\n  <author><br \/>\n    <name>Aaron Skonnard<\/name><br \/>\n  <\/author><br \/>\n  <entry><br \/>\n    <title>1st blog entry<\/title>\n    <link>http:\/\/skonnard.com\/blog\/entry1<\/link>\n    <created>2004-01-13T17:16:44.9803903-07:00<\/created><br \/>\n    <content type=\"text\/html\" mode=\"xml\"><br \/>\n      <body xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><\/p>\n<p>This is my first blog entry<\/p>\n<p>      <\/body><br \/>\n    <\/content><br \/>\n  <\/entry><br \/>\n  <entry><br \/>\n    <title>2nd blog entry<\/title>\n    <link>http:\/\/skonnard.com\/blog\/entry2<\/link>\n    <created>2004-01-13T17:16:45.9803903-07:00<\/created><br \/>\n    <content type=\"text\/html\" mode=\"xml\"><br \/>\n      <body xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><\/p>\n<p>This is my second blog entry<\/p>\n<p>      <\/body><br \/>\n    <\/content><br \/>\n  <\/entry><br \/>\n<\/feed><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nFigure 4 Sample Blogroll (OPML)<\/p>\n<p><opml><br \/>\n  <head> <title>Aaron&#8217;s Favorite Blogs<\/title> <\/head><br \/>\n  <body><br \/>\n    <outline type=\"rss\" title=\"PDC Bloggers\" \n      description=\"PDC Bloggers website\" \n      xmlUrl=\"http:\/\/pdcbloggers.net\/Feed.rss\" \n      htmlUrl=\"http:\/\/PDCBloggers.net\" \/><br \/>\n    <outline type=\"rss\" title=\"MSDN Magazine: Current Issue\" \n      description=\"The Microsoft Journal for Developers\" \n      xmlUrl=\"http:\/\/msdn.microsoft.com\/msdnmag\/rss\/recent.xml\" \n      htmlUrl=\"http:\/\/msdn.microsoft.com\/msdnmag\/\" \/><br \/>\n    <outline type=\"rss\" title=\"MSDN Just Published\" \n      description=\"Keep current ...\" \n      xmlUrl=\"http:\/\/msdn.microsoft.com\/rss.xml\"  \n      htmlUrl=\"http:\/\/msdn.microsoft.com\/\" \/><br \/>\n  <\/body><br \/>\n<\/opml><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nFigure 5 Generating an RSS 2.0 Feed in ASP.NET<\/p>\n<p><%@ Page language=\"c#\" Codebehind=\"rss.aspx.cs\" \n    AutoEventWireup=\"false\" Inherits=\"SimpleBlog.rss\" %><br \/>\n<rss version=\"2.0\"><br \/>\n  <channel><br \/>\n    <title>My Blog<\/title>\n    <link>http:\/\/localhost\/simpleblog\/default.aspx<\/link>\n    <description>A weblog about nothing&#8230;<\/description><br \/>\n    <language>en-us<\/language><br \/>\n    <asp:Repeater id=\"Items\" runat=\"server\"><br \/>\n      <ItemTemplate><br \/>\n        <item><br \/>\n        <title><%#DataBinder.Eval(Container.DataItem,\n            \"title\")%><\/title><br \/>\n        <description><%#DataBinder.Eval(\n            Container.DataItem,\"description\")%><\/description>\n        <pubDate><%#DataBinder.Eval(Container.DataItem, \n            \"pubdate\") %><\/pubDate>\n        <link><%# DataBinder.Eval(Container.DataItem, \"link\") %><\/link>\n        <\/item><br \/>\n      <\/ItemTemplate><br \/>\n    <\/asp:Repeater><br \/>\n  <\/channel><br \/>\n<\/rss><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nFigure 6 RSS Aggregator Web User Control<\/p>\n<p><%@ Control Language=\"c#\" AutoEventWireup=\"true\" \n    EnableViewState=\"false\" Debug=\"true\"%><br \/>\n<%@ Import namespace=\"System.Xml\" %><br \/>\n<%@ OutputCache Duration=\"1800\" VaryByParam=\"none\" %><br \/>\n<script runat=\"server\" language=\"C#\">\nprivate void Page_Load(object sender, System.EventArgs e)\n{\n  StringBuilder sb = new StringBuilder();\n  XmlDocument doc = new XmlDocument();\n  doc.Load(Server.MapPath(\"blogroll.opml\"));\n  int numToDisp = int.Parse(doc.SelectSingleNode(\n    \"\/opml\/@numberToDisplay\").InnerText);\n  XmlNodeList rss = doc.SelectNodes(\"\/\/outline\/@xmlUrl\");\n  foreach (XmlNode r in rss)\n  {\n    XmlDocument blogdoc = new XmlDocument();\n    blogdoc.Load(r.Value);\n    XmlNodeList items = blogdoc.SelectNodes(\"\/\/item\");  \n    for (int i=0; i<items.Count &#038;&#038; i<numToDisp; i++)\n    {\n      string author=\"\";\n      XmlNode authorNode = items[i].SelectSingleNode(\n       \"*[local-name()='author' or local-name()='creator']\");\n      if (authorNode != null) author = authorNode.InnerText;\n      sb.Append(String.Format(\n        \"&#149;&nbsp;<a href={0}>{1} ({2})<\/a><br \/>\",\n        items[i].SelectSingleNode(\"link\").InnerText,\n        items[i].SelectSingleNode(\"title\").InnerText, author));\n    }        \n  }\n  EntriesHTML.Text = sb.ToString();\n}\n<\/script><\/p>\n<style> <!-- styles omitted for brevity --> ...  <\/style>\n<div class=\"title\">UNUG Blogs<\/div>\n<p><asp:Literal id=\"EntriesHTML\" runat=\"server\"><\/asp:Literal><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Figure 1 Sample RSS 1.0 Document The XML Files http:\/\/s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[115,426],"class_list":["post-1599","post","type-post","status-publish","format-standard","hentry","category-dotnet","tag-asp-net","tag-rss"],"views":332,"_links":{"self":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/1599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1599"}],"version-history":[{"count":0,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/1599\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1599"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}