Web 2.0 is a new generation Internet model centered on personalization represented by Blog, Wike, Tag, RSS and other technologies. RSS does not seem to be too popular compared to terms such as Blog. However, when opening a web page, there are
still
eye-catching icons such as RSS and,as follows:
1using System;
2using System.Xml;
3using System.Collections;
4using System.Globalization;
5using System.Web;
6
7namespace BLRL
8{
9 /// <summary>
10 /// Summary description for Rss.
11 /// </summary>
12 public class Rss
13 {
14 const string dublinCoreNamespaceUri = @" http://purl.org/dc/elements/1.1/ ";
15 const string slashNamespaceUri = @" http://purl.org/rss/1.0/modules/slash/ ";
16 const string syndicationNamespaceUri = @" http://purl.org/rss/1.0/modules/syndication/ ";
17 //RSS channel structure
18 struct RssChannel
19 {
20 public string title;//title
21 public string link;//connection
22 public string language;//language
23 public string description;//description
24 public string webMaster;//Publisher
25}
26
27 //RSS picture information
28 struct RssImage
29 {
30 public string url;//address
31 public string title;//title
32 public int height;//height
33 public int width;//length
34}
35
36 //RSS item structure
37 struct RssItem
38 {
39 public string title;//title
40 public string catalog;//category
41 public string link;//connection
42 public DateTime pubDate;//Publish date
43 public string description;//description
44
45 }
46 public Rss()
47 {
48 //
49 // TODO: Add constructor logic here
50 //
51 }
52 /// <summary>
53 ///Add rss version information
54 /// </summary>
55 /// <param name="xmlDocument"></param>
56 /// <returns></returns>
57 public static XmlDocument AddRssPreamble(XmlDocument xmlDocument)
58 {
59 //Declaration to create version 1.0 xml
60 XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null);
61 xmlDocument.InsertBefore(xmlDeclaration, xmlDocument.DocumentElement);
62
63 XmlElement rssElement = xmlDocument.CreateElement("rss");
64
65 XmlAttribute rssVersionAttribute = xmlDocument.CreateAttribute("version");
66 rssVersionAttribute.InnerText = "2.0";
67 rssElement.Attributes.Append(rssVersionAttribute);
68 xmlDocument.AppendChild(rssElement);
69
70
71 XmlAttribute dublicCoreNamespaceUriAttribute = xmlDocument.CreateAttribute("xmlns:dc");
72 dublicCoreNamespaceUriAttribute.InnerText = dublinCoreNamespaceUri;
73 rssElement.Attributes.Append(dublicCoreNamespaceUriAttribute);
74
75 XmlAttribute slashNamespaceUriAttribute = xmlDocument.CreateAttribute("xmlns:slash");
76 slashNamespaceUriAttribute.InnerText = slashNamespaceUri;
77 rssElement.Attributes.Append(slashNamespaceUriAttribute);
78
79 XmlAttribute syndicationNamespaceUriAttribute = xmlDocument.CreateAttribute("xmlns:sy");
80 syndicationNamespaceUriAttribute.InnerText = syndicationNamespaceUri;
81 rssElement.Attributes.Append(syndicationNamespaceUriAttribute);
82
83
84 return xmlDocument;
85}
86
87 /// <summary>
88 /// Add channel
89 /// </summary>
90 /// <param name="xmlDocument"></param>
91 /// <param name="channel"></param>
92 /// <returns></returns>
93 private static XmlDocument AddRssChannel(XmlDocument xmlDocument, RssChannel channel)
94 {
95 XmlElement channelElement = xmlDocument.CreateElement("channel");
96 XmlNode rssElement = xmlDocument.SelectSingleNode("rss");
97
98 rssElement.AppendChild(channelElement);
99
100 //Add title
101 XmlElement channelTitleElement = xmlDocument.CreateElement("title");
102 channelTitleElement.InnerText = channel.title;
103 channelElement.AppendChild(channelTitleElement);
104
105 //Add connection
106 XmlElement channelLinkElement = xmlDocument.CreateElement("link");
107 channelLinkElement.InnerText = channel.link;
108 channelElement.AppendChild(channelLinkElement);
109
110 //Add description
111 XmlElement channelDescriptionElement = xmlDocument.CreateElement("description");
112 XmlCDataSection cDataDescriptionSection = xmlDocument.CreateCDataSection(channel.description);
113 channelDescriptionElement.AppendChild(cDataDescriptionSection);
114 channelElement.AppendChild(channelDescriptionElement);
115
116 //Add language
117 XmlElement languageElement = xmlDocument.CreateElement("language");
118 languageElement.InnerText = channel.language;
119 channelElement.AppendChild(languageElement);
120
121 //Add publisher
122 XmlElement webMasterElement = xmlDocument.CreateElement("webMaster");
123 webMasterElement.InnerText = channel.webMaster;
124 channelElement.AppendChild(webMasterElement);
125
126 return xmlDocument;
127 }
128
129
130 //Add RssImage
131 private static XmlDocument AddRssImage(XmlDocument xmlDocument, RssImage img)
132 {
133 XmlElement imgElement = xmlDocument.CreateElement("image");
134 XmlNode channelElement = xmlDocument.SelectSingleNode("rss/channel");
135
136 //Create title
137 XmlElement imageTitleElement = xmlDocument.CreateElement("title");
138 imageTitleElement.InnerText = img.title;
139 imgElement.AppendChild(imageTitleElement);
140
141 //Create address
142 XmlElement imageUrlElement = xmlDocument.CreateElement("url");
143 imageUrlElement.InnerText = img.url;
144 imgElement.AppendChild(imageUrlElement);
145
146 //Create height
147 XmlElement imageHeightElement = xmlDocument.CreateElement("height");
148 imageHeightElement.InnerText = img.height.ToString();
149 imgElement.AppendChild(imageHeightElement);
150
151 //Create length
152 XmlElement imageWidthElement = xmlDocument.CreateElement("width");
153 imageWidthElement.InnerText = img.width.ToString();
154 imgElement.AppendChild(imageWidthElement);
155
156 //Add the image node to the channel node
157 channelElement.AppendChild(imgElement);
158 return xmlDocument;
159
160 }
161
162
163 /// <summary>
164 /// Add item information
165 /// </summary>
166 /// <param name="xmlDocument"></param>
167 /// <param name="item"></param>
168 /// <returns></returns>
169 private static XmlDocument AddRssItem (XmlDocument xmlDocument, RssItem item)
170 {
171 XmlElement itemElement = xmlDocument.CreateElement("item");
172 XmlNode channelElement = xmlDocument.SelectSingleNode("rss/channel");
173
174 //Create title
175 XmlElement itemTitleElement = xmlDocument.CreateElement("title");
176 XmlCDataSection cDataTitleSection = xmlDocument.CreateCDataSection(item.title);
177 itemTitleElement.AppendChild(cDataTitleSection);
178 itemElement.AppendChild(itemTitleElement);
179
180 //Creation date
181 XmlElement pubDateElement = xmlDocument.CreateElement("pubDate");
182 pubDateElement.InnerText = XmlConvert.ToString(item.pubDate.ToUniversalTime(), "yyyy-MM-ddTHH:mm:ss");
183 itemElement.AppendChild(pubDateElement);
184
185 //Add connection
186 XmlElement itemLinkElement = xmlDocument.CreateElement("link");
187 itemLinkElement.InnerText = item.link;
188 itemElement.AppendChild(itemLinkElement);
189
190 //Create description
191 XmlElement itemDescriptionElement = xmlDocument.CreateElement("description");
192 XmlCDataSection cDataDescriptionSection = xmlDocument.CreateCDataSection(item.description);
193 itemDescriptionElement.AppendChild(cDataDescriptionSection);
194 itemElement.AppendChild(itemDescriptionElement);
195
196
197 //Create type
198 XmlElement itemcatalogElement = xmlDocument.CreateElement("catalog");
199 itemcatalogElement.InnerText = item.catalog;
200 itemElement.AppendChild(itemcatalogElement);
201
202 //Add RssItem to the channel node
203 channelElement.AppendChild(itemElement);
204
205 return xmlDocument;
206 }
207 }
208}
According to specific needs, you can first read the data into the list, then traverse the list, call the above method, and generate an Xml string.
This string is the XML string used by RS. You can also enter an aspx file, and then use <link type="application/rss+xml" rel="alternate" href="rssfeed.aspx"> to call the RSS file, and software such as the toilet will automatically prompt for RRS information
http: //jillzhang.cnblogs.com/archive/2006/06/11/423086.html