Web2.0时是以Blog,Wike,Tag,RSS等技术为代表的以个性化为中心的新一代互联网模式,RSS比起Blog等名词似乎还不算太热。但打开网页仍是遍布了RSS,Xml等醒目的图标,打开页面Mathon浏览器也是一个劲的提示有新的RSS连接,前一段一个项
目需要,自己写了一个.Net下面生成RSS信息的类,如下:
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频道结构
18 struct RssChannel
19 {
20 public string title;//标题
21 public string link;//连接
22 public string language;//语言
23 public string description;//描述
24 public string webMaster;//发布者
25 }
26
27 //RSS图片信息
28 struct RssImage
29 {
30 public string url;//地址
31 public string title;//标题
32 public int height ;//高度
33 public int width;//长度
34 }
35
36 //RSS项结构
37 struct RssItem
38 {
39 public string title;//标题
40 public string catalog;//类别
41 public string link;//连接
42 public DateTime pubDate;//发布日期
43 public string description;//描述
44
45 }
46 public Rss()
47 {
48 //
49 // TODO: Add constructor logic here
50 //
51 }
52 /// <summary>
53 ///添加rss版本信息
54 /// </summary>
55 /// <param name="xmlDocument"></param>
56 /// <returns></returns>
57 public static XmlDocument AddRssPreamble( XmlDocument xmlDocument)
58 {
59 //声明创建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 /// 添加频道
89 /// </summary>
90 /// <param name="xmlDocument"></param>
91 /// <param name="channel"></param>
92 /// <returns></returns>
93 private static XmlDocument AddRssChannel( XmlDocument xmlDocument, Rs