Simple RSS Feed

Source: Internet
Author: User
Author: Peter Bernhardt
3 leaf development

August 2005

I wrote a conclusion many years ago, that is, I still have no idea about everything in the world. I don't know. In fact, it's quite self-developed to see the world from the very beginning, but I'm crazy, but now I am very humble. In fact, in the time of the online network, this is just a sudden increase, just like I cannot keep up with the endless online moments, new insights, and opinions. I don't know how to keep up with the latest development steps in Visual Basic, Visual C #, And. NET Framework.

Therefore, I want to explore other methods in the next article to apply the technology that you may already be familiar with: RSS (full name Really Simple Syndication ), this cutting edge technology is the best tool for storing excessive economic resources.

First, we provide some information for beginners, A Baidu-based website wikpedia's solution to RSS is "website content overview and summary to full-text content Content Overview. These resources are stored in the form of an XML case. The case involves RSS feed, webfeed, RSS feed stream, or RSS channel. In order to facilitate information integration, RSS allows regular users on the website to use the new website summary tool to catch up with website updates .」 (For the full text, see the wikpedia website's description of RSS ).

This article starts with a simple RSS feed fetch program, allowing you to build a feed with Visual Web Developer 2005 express edition. I will create a controller that retrieves an RSS feed on the website and groups the content to display on the website. You can also build the RSS feed fetch program into a Windows application. If you want to collect information for private use, you can also use the free-of-choice RSS client applications (such as RSS reader or sharpreader ). However, using volumes in Web applications has advantages, allowing you to expand your own content, and provides website creators with rich experience.

Before developing a program, let's take a look at the typical RSS 2.0 trial program. In this example, the metadata provider is Microsoft's msdn website, and I use feed for Visual Basic content.

<rss  xmlns:msdn="http://msdn.microsoft.com/aboutmsdn/rss/"  xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:msdndomain="http://msdn.microsoft.com/aboutmsdn/rss/domains"  version="2.0">  <channel>    <title>MSDN: Visual Basic</title>    <link>http://msdn.microsoft.com/vbasic/</link>    <description>Recently Published Visual Basic Content</description>    <language>en-us</language>    <pubDate>Thu, 30 Jun 2005 13:01:02 GMT</pubDate>    <lastBuildDate>Thu, 30 Jun 2005 13:01:02 GMT</lastBuildDate>    <generator>MSDN RSS Service 1.1.0.0</generator>    <ttl>1440</ttl>    <item>      <title>June CTP of Visual Studio 2005 Available to MSDN Subscribers</title>      <description>The latest Community Technical Preview of Visual Studio 2005 is now available for download to MSDN subscribers.</description>      <link>http://msdn.microsoft.com/subscriptions/</link>      <category domain="msdndomain:ContentType">Announcement</category>      <category domain="msdndomain:Subject">.NET development</category>      <msdn:headlineImage>http://msdn.microsoft.comicons/article.gif</msdn:headlineImage>      <msdn:contentType>Announcement</msdn:contentType>      <msdn:simpleDate>Jun 27</msdn:simpleDate>      <guid isPermaLink="false">Titan_1106</guid>      <pubDate>Tue, 28 Jun 2005 02:00:13 GMT</pubDate>    </item>    <!-- more items follow -->  </channel></rss>

In a typical feed case, there are various types of resources, some of which will be merged by the combination of information providers (taking the msdn standard image as an example, it is not a benchmark ). The XML structure is close to zookeeper.<channel> Click here, which contains a topic and a description of the content list that can be used to introduce content.<channel> There are many sub-accounts in the region<item> To represent each internal article (including the topic, description, release date, and end to the full text ).

After creating a new website in Visual Web Developer 2005 express edition, I added a Web user control role to it to display information.

(Click the image to zoom in)

ASP. one of the functions of NET 2.0 is that it supports the code-behind model that Visual Studio 2003 developers are familiar with, and also supports embedded program programming (new features ), allows you. aspx or. in the ascx Flood case<script>Create all program libraries. However, using the embedded program does not affect ASP. net, but I personally prefer program post-configuration models and will use this method in this example. You will also find that I use Visual Basic to compile the program of the application.

In the design tool, I addedRepeaterControl worker, thisRepeaterIt is a data link control component that can use its own layout to display information, this is very convenient for displaying the content in the RSS feed. You can use the smart tagging function that is related to the control, set the resource source for controlling the volume in the design segment, as shown in the following figure. However, in this application, I will use RSS feed to set the source in the response segment.

(Click the image to zoom in)

In the past, it is switched. ascx upload case (rsslist. ascx. VB) program later, I named it blank (including the class required for obtaining RSS feed) plusImportsOtherwise, the existence of the legal case will be terminated.Repeater.

Imports System.NetImports System.Data

WhilePage LoadIn terms of events, I used the event handling formula. In addition, I addedRefreshfeedPrivate helper function. In this way, you can obtain the RSS feed andDatasetReturnsPage LoadEvent handling regular. InRefreshfeedIn the form, the first itinerary will be usedWebrequestSimilar sharingCreateFunction, establishHttpwebrequestObjects.

Dim rssFeed As HttpWebRequest = DirectCast(WebRequest.Create("http://msdn.microsoft.com/vbasic/rss.xml"), HttpWebRequest)

ToCreateThe Program uploads the target URL of the RSS feed, and returnsHttpwebrequestObject, which is a special typeWebrequestObject, supporting other features and methods to facilitate interaction between HTTP and server. In this exampleHttpwebrequestIt is easy to understand. The Program Scheduler first obtains the Server Response (Getresponse), And then the response format is XML, so the response stream (Getresponsestream) You can useStreamAs an incoming referenceReadxmlMultiple methods are available.Dataset.

Dim rssData As DataSet = New DataSet()rssData.ReadXml(rssFeed.GetResponse().GetResponseStream())

ReadxmlThe method will trigger the structure description of XML data.<channel> And<items>ClickDatasetHere is a differentDatatableTo present. InPage LoadIn the event handling function, callRefereshfeedMethod to retrieveDatasetLater, the program will access the channel and object information in different ways.DatasetThe secondDatatableContains channel information. The program usesRowOfItemarrayCompile, column the first row of information fromDatatableUpload to oneObjectRegion column. Next, I want to confirm that the location of the resource is correct, so let the program engineer assign the standard and the original location of the descriptionIntegerType. The program will invoke calls with these valuesObjectTheGetvalueMethod To save the values related to each item to something elseFriendSecond bit (I am inRepeaterThese values are used in the control worker ).

Dim channelItems As Object() = rssData.Tables(1).Rows(0).ItemArrayDim titleColumn As Integer = rssData.Tables(1).Columns("title").OrdinalDim descriptionColumn As Integer = rssData.Tables(1).Columns("description").OrdinalTitle = channelItems.GetValue(titleColumn).ToString()Description = channelItems.GetValue(descriptionColumn).ToString()

In the past, the program will contain content from the RSS feed.DatasetMedium, forwardRepeaterTheDatasourceExperimental settingsDatatable. Finally, the program will callRepeaterOfDatbindMethod.

Repeater1.DataSource = rssData.Tables(2)Repeater1.DataBind() 

InRssfeed. ascxIn the resource category of the control role, I joinedRepeaterControls the metadata of a volume to display information. In<HeaderTemplate>In, the program Program program uses a header that can display channel standards and descriptions as the table opening end.

<HeaderTemplate>
<table border=0 style="width: 240px; font-size: x-small; color: black; font-family: Verdana;">
<thead>
<tr style="font-weight: bold;">
<td><%#Me.Title%></td>
</tr>
<tr style="font-style: italic;">
<td><%#Me.Description%></td>
</tr>
</thead>
</HeaderTemplate>

In the same way<ItemTemplate>In, the program displays the link between content and content, and the description of content.

<ItemTemplate>   <tr bgcolor="LightBlue"  >       <td>           <a target="article" style="text-decoration: none; color: black;" href=<%# DataBinder.Eval(Container.DataItem, "link") %>>            <%# DataBinder.Eval(Container.DataItem, "title") %> </a>        </td>    </tr>    <tr bgcolor="Ivory">        <td style="color: CornFlowerBlue;">           <%# DataBinder.Eval(Container.DataItem, "description") %>        </td>   </tr></ItemTemplate>

The last and most important step, I addedOutputcacheIndicates that the cache processing controls a period of time.

<%@ OutputCache Duration="3600" VaryByParam="None" %>

So,RefreshfeedThe function is not used once every time the user accesses the interface containing the control token. If this is not done, when the load on my website is large, it may cause a large amount of traffic between the Web server and the partner information provider. The following figure shows how to merge the application content:

(Click the image to zoom in)

I will explore in future articles how to integrate RSS feeds in Web applications, but before that, I suggest you refer to this article as a regular example. Let's take a look at it manually.

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.