• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-6-30 23:38 | 作者: admin | 来源: | 查看: 60次 | 进入软件测试论坛讨论

领测软件测试网 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>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网