. Net/C #: Use reflection to compile a reader for general rss 2.0

Source: Internet
Author: User
Tags xml attribute

/*
. Net/C #: Use reflection to compile a reader for general rss 2.0
I recently wrote a Simple Rss Reader.
There are two types of off-the-shelf code found on the Internet:
1. The code is simple, but not general enough (for example, some special rss reader on this site)
2. The code is complex, but there is not enough time to digest it (for example, rssbandit)
Start by yourself:
We have all the basic attributes of rss!
But some special non-General attributes, such:
Slash: comments
Wfw: comment
Wfw: commentRss
Trackbackping
Not necessarily exist! What should I do ???
I thought of Reflection and proposed the following solutions:
1. Class RssHeader is used to indicate the Rss header information
You can add a new attribute to it in the following way:
The member variable Fieild is named rss. The attribute name corresponding to the XML source is prefixed with an underscore. The XML Attribute name contains ":" to filter it out!
For example, <dc: language> zh-CHS </dc: language>
Picture it:
Private string _ dclanguage
Public string DcLanguage
{
Get
{
Return this. _ dclanguage;
}
}
2. Class RssItem is used to represent the Rss Item
The rule for adding new attributes is the same as RssHeader!
3. Retrieve the rss XML source and recursively traverse the node (class SimpleRssReader)
According to the actual rss attributes, through reflection, "construct and instantiate" RssHeader and RssItem!
Please refer to the Travel method of class SimpleRssReader carefully!
4. Database (this article uses Micrshaoft Data Access Application Block 3.1)
Table:
Channels (main table)
ChannelsDetails (detail table)
The field name and its data type strictly follow the attribute name corresponding to the rss XML source. The XML Attribute name contains ":" to filter it out!
Stored Procedure:
SP_AddChannel
SP_AddChannelsDetails
The parameter name and its data type are strictly in accordance with the attribute name corresponding to the rss XML source. The XML Attribute name contains ":" to filter it out!

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.