Generate RSS 2.0 Feed in asp.net page

Source: Internet
Author: User
Tags eval resource xmlns
asp.net|rss| page Figure 1 Sample RSS 1.0 Document


&LT;RDF:RDF xmlns:rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns= "http://purl.org/rss/1.0/" 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= "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 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 are my second blog entry. </description> <dc:date>2004-01-13T17:16:45.9803903-07:00</dc:date> &LT;/ITEM&GT;&LT;/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 i-I-entry.</description> < pubdate>wed, 17:16:44 gmt</pubdate> </item> <item> <title>2nd Blog entry</ Title> <link>http://skonnard.com/blog/entry1</link> <description>this are my second blog entry </description> <pubdate>wed, 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 i-i-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" > &LT;P&GT This is my second blog entry</p> </body> </content> </entry></feed>
Figure 4 Sample blogroll (OPML)

<opml> Figure 5 Generating an RSS 2.0 feeds 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>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.