| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- //
- // RSS.cs: Some utility classes to generate RSS feeds
- //
- // (C) 2002 Miguel de Icaza ([email protected])
- //
- //
- using System;
- using System.Xml;
- using System.IO;
- namespace RSS {
- public class Item {
- XmlDocument doc;
- XmlNode item;
- XmlText title, link, description;
-
- public Item (XmlDocument doc, XmlNode item)
- {
- this.doc = doc;
- this.item = item;
- }
- XmlText MakeTextElement (string name)
- {
- XmlNode node = doc.CreateElement (name);
- XmlText text = doc.CreateTextNode ("");
-
- item.AppendChild (node);
- node.AppendChild (text);
-
- return text;
- }
- public string Title {
- get {
- if (title == null)
- return null;
- return title.Value;
- }
- set {
- if (title == null)
- title = MakeTextElement ("title");
- title.Value = value;
- }
- }
- public string Link {
- get {
- if (link == null)
- return null;
- return link.Value;
- }
- set {
- if (link == null)
- link = MakeTextElement ("link");
- link.Value = value;
- }
- }
- public string Description {
- get {
- if (description == null)
- return null;
- return description.Value;
- }
- set {
- if (description == null)
- description = MakeTextElement ("description");
- description.Value = value;
- }
- }
- }
-
- public class Channel {
- XmlDocument doc;
- XmlNode channel;
- XmlText title, link, description, language, pubDate, lastBuildDate;
- XmlText managingEditor, webMaster;
-
- XmlText MakeTextElement (string name)
- {
- XmlNode node = doc.CreateElement (name);
- XmlText text = doc.CreateTextNode ("");
-
- channel.AppendChild (node);
- node.AppendChild (text);
-
- return text;
- }
-
- public Channel (XmlDocument doc, XmlNode node)
- {
- this.channel = node;
- this.doc = doc;
-
- title = MakeTextElement ("title");
- link = MakeTextElement ("link");
- description = MakeTextElement ("description");
- }
- public Item NewItem ()
- {
- XmlNode node = doc.CreateElement ("item");
- Item item;
- channel.AppendChild (node);
- item = new Item (doc, node);
- return item;
- }
-
- public string Title {
- get {
- return title.Value;
- }
-
- set {
- title.Value = value;
- }
- }
-
- public string Link {
- get {
- return link.Value;
- }
- set {
- link.Value = value;
- }
- }
- public string Description {
- get {
- return description.Value;
- }
- set {
- description.Value = value;
- }
- }
- #region Optional Values
- public string ManagingEditor {
- get {
- if (managingEditor == null)
- return null;
-
- return managingEditor.Value;
- }
- set {
- if (managingEditor == null)
- managingEditor = MakeTextElement ("managingEditor");
- managingEditor.Value = value;
- }
- }
- public string WebMaster {
- get {
- if (webMaster == null)
- return null;
-
- return webMaster.Value;
- }
- set {
- if (webMaster == null)
- webMaster = MakeTextElement ("webMaster");
- webMaster.Value = value;
- }
- }
- public string PubDate {
- get {
- if (pubDate == null)
- return null;
- return pubDate.Value;
- }
- set {
- if (pubDate == null)
- pubDate = MakeTextElement ("pubDate");
- pubDate.Value = value;
- }
- }
- public string LastBuildDate {
- get {
- if (lastBuildDate == null)
- return null;
- return lastBuildDate.Value;
- }
- set {
- if (lastBuildDate == null)
- lastBuildDate = MakeTextElement ("lastBuildDate");
- lastBuildDate.Value = value;
- }
- }
- public string Language {
- get {
- if (language == null)
- return null;
- return language.Value;
- }
- set {
- if (language == null)
- language = MakeTextElement ("language");
- language.Value = value;
- }
- }
- #endregion
- }
-
- class RSS {
- XmlDocument doc;
- XmlNode rss;
-
- const string rss_base =
- "<?xml version=\"1.0\"?> <rss version=\"0.92\"></rss>";
-
- public RSS ()
- {
- doc = new XmlDocument ();
-
- doc.LoadXml (rss_base);
- rss = doc.DocumentElement;
- }
-
- public Channel NewChannel (string title, string url)
- {
- XmlNode node = doc.CreateElement ("channel");
- Channel c;
-
- rss.AppendChild (node);
- c = new Channel (doc, node);
-
- return c;
- }
-
- public XmlDocument XmlDocument {
- get {
- return doc;
- }
- }
- }
- }
|