分享
 
 
 

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

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有