private void writeChannel(RssChannel channel) { if (Writer == null) throw new InvalidOperationException("RssWriter has been closed, and cannot be written to."); if (channel == null) throw new ArgumentNullException("Channel must be instanciated with data to be written."); if (ChannelBegun) Writer.WriteEndElement(); else ChannelBegun = true; BeginDocument(); Writer.WriteStartElement("channel"); WriteElement("title", channel.Title, true); WriteElement("description", channel.Description, true); WriteElement("link", channel.Link, true); if (channel.Image != null) { Writer.WriteStartElement("image"); WriteElement("title", channel.Image.Title, true); WriteElement("url", channel.Image.Url, true); WriteElement("link", channel.Image.Link, true); WriteElement("description", channel.Image.Description, false); WriteElement("width", channel.Image.Width, false); WriteElement("height", channel.Image.Height, false); Writer.WriteEndElement(); } WriteElement("language", channel.Language, Version == RssVersion.RSS091); WriteElement("copyright", channel.Copyright, false); WriteElement("managingEditor", channel.ManagingEditor, false); WriteElement("webMaster", channel.WebMaster, false); WriteElement("pubDate", channel.PubDate, false); WriteElement("lastBuildDate", channel.LastBuildDate, false); if (channel.Docs != RssDefault.String) WriteElement("docs", channel.Docs, false); else WriteElement("docs", "http://backend.userland.com/rss", false); WriteElement("rating", channel.Rating, false); WriteSkipDays(channel); WriteSkipHours(channel); if (channel.Categories != null) foreach(RssCategory category in channel.Categories) { if (category.Name != RssDefault.String) { Writer.WriteStartElement("category"); WriteAttribute("domain", category.Domain, false); Writer.WriteString(category.Name); Writer.WriteEndElement(); } } if (channel.Cloud != null) { Writer.WriteStartElement("cloud"); WriteElement("domain", channel.Cloud.Domain, false); WriteElement("port", channel.Cloud.Port, false); WriteElement("path", channel.Cloud.Path, false); WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false); if (channel.Cloud.Protocol != RssCloudProtocol.Empty) WriteElement("Protocol", channel.Cloud.Protocol, false); Writer.WriteEndElement(); } if (channel.Generator != RssDefault.String) WriteElement("generator", channel.Generator, false); else WriteElement("generator", "RSS.NET: http://rss-net.sf.net/", false); WriteElement("ttl", channel.TimeToLive, false); // RSS Modules foreach(RssModule rssModule in this._rssModules) { if(rssModule.IsBoundTo(channel.GetHashCode())) { foreach(RssModuleItem rssModuleItem in rssModule.ChannelExtensions) { if(rssModuleItem.SubElements.Count == 0) WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text, rssModuleItem.IsRequired); else writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix); } } } if (channel.TextInput != null) { Writer.WriteStartElement("textinput"); WriteElement("title", channel.TextInput.Title, true); WriteElement("description", channel.TextInput.Description, true); WriteElement("name", channel.TextInput.Name, true); WriteElement("link", channel.TextInput.Link, true); Writer.WriteEndElement(); } foreach (RssItem item in channel.Items) { writeItem(item, channel.GetHashCode()); } Writer.Flush(); }
private void writeChannel(RssChannel channel) { if (writer == null) { throw new InvalidOperationException("RssWriter has been closed, and can not be written to."); } if (channel == null) { throw new ArgumentNullException("Channel must be instanciated with data to be written."); } if (wroteChannel) { writer.WriteEndElement(); } else { wroteChannel = true; } BeginDocument(); writer.WriteStartElement("channel"); WriteElement("title", channel.Title, true); WriteElement("description", channel.Description, true); WriteElement("link", channel.Link, true); if (channel.Image != null) { writer.WriteStartElement("image"); WriteElement("title", channel.Image.Title, true); WriteElement("url", channel.Image.Url, true); WriteElement("link", channel.Image.Link, true); switch (rssVersion) { case RssVersion.RSS091: case RssVersion.RSS092: case RssVersion.RSS20: WriteElement("description", channel.Image.Description, false); WriteElement("width", channel.Image.Width, false); WriteElement("height", channel.Image.Height, false); break; } writer.WriteEndElement(); } switch (rssVersion) { case RssVersion.RSS091: case RssVersion.RSS092: case RssVersion.RSS20: WriteElement("language", channel.Language, rssVersion == RssVersion.RSS091); WriteElement("copyright", channel.Copyright, false); WriteElement("managingEditor", channel.ManagingEditor, false); WriteElement("webMaster", channel.WebMaster, false); WriteElement("pubDate", channel.PubDate, false); WriteElement("lastBuildDate", channel.LastBuildDate, false); if (channel.Docs != RssDefault.String) { WriteElement("docs", channel.Docs, false); } else { switch (rssVersion) { case RssVersion.RSS091: WriteElement("docs", "http://my.netscape.com/publish/formats/rss-spec-0.91.html", false); break; case RssVersion.RSS092: WriteElement("docs", "http://backend.userland.com/rss092", false); break; case RssVersion.RSS20: WriteElement("docs", "http://backend.userland.com/rss", false); break; } } WriteElement("rating", channel.Rating, false); string[] Days = {"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}; for (int i = 0; i <= 6; i++) { if (channel.SkipDays[i]) { writer.WriteStartElement("skipDays"); for (int i2 = 0; i2 <= 6; i2++) { if (channel.SkipDays[i2]) { WriteElement("day", Days[i2], false); } } writer.WriteEndElement(); break; } } for (int i = 0; i <= 23; i++) { if (channel.SkipHours[i]) { writer.WriteStartElement("skipHours"); for (int i2 = 0; i2 <= 23; i2++) { if (channel.SkipHours[i2]) { WriteElement("hour", i2 + 1, false); } } writer.WriteEndElement(); break; } } break; } switch (rssVersion) { case RssVersion.RSS092: case RssVersion.RSS20: if (channel.Categories != null) { foreach (RssCategory category in channel.Categories) { if (category.Name != RssDefault.String) { writer.WriteStartElement("category"); WriteAttribute("domain", category.Domain, false); writer.WriteString(category.Name); writer.WriteEndElement(); } } } if (channel.Cloud != null) { writer.WriteStartElement("cloud"); WriteElement("domain", channel.Cloud.Domain, false); WriteElement("port", channel.Cloud.Port, false); WriteElement("path", channel.Cloud.Path, false); WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false); if (channel.Cloud.Protocol != RssCloudProtocol.Empty) { WriteElement("Protocol", channel.Cloud.Protocol, false); } writer.WriteEndElement(); } break; } if (rssVersion == RssVersion.RSS20) { if (channel.Generator != RssDefault.String) { WriteElement("generator", channel.Generator, false); } else { WriteElement("generator", "RSS.NET: http://www.rssdotnet.com/", false); } WriteElement("ttl", channel.TimeToLive, false); // RSS Modules foreach (RssModule rssModule in this._rssModules) { if (rssModule.IsBoundTo(channel.GetHashCode())) { foreach (RssModuleItem rssModuleItem in rssModule.ChannelExtensions) { if (rssModuleItem.SubElements.Count == 0) { WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text, rssModuleItem.IsRequired); } else { writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix); } } } } } if (channel.TextInput != null) { writer.WriteStartElement("textinput"); WriteElement("title", channel.TextInput.Title, true); WriteElement("description", channel.TextInput.Description, true); WriteElement("name", channel.TextInput.Name, true); WriteElement("link", channel.TextInput.Link, true); writer.WriteEndElement(); } foreach (RssItem item in channel.Items) { writeItem(item, channel.GetHashCode()); } writer.Flush(); }
private void writeChannel(RssChannel channel) { if (writer == null) { throw new InvalidOperationException("RssWriter has been closed, and can not be written to."); } if (channel == null) { throw new ArgumentNullException("Channel must be instanciated with data to be written."); } if (wroteChannel) { writer.WriteEndElement(); } else { wroteChannel = true; } BeginDocument(); writer.WriteStartElement("channel"); WriteElement("title", channel.Title, true); WriteElement("description", channel.Description, true); WriteElement("link", channel.Link, true); if (channel.Image != null) { writer.WriteStartElement("image"); WriteElement("title", channel.Image.Title, true); WriteElement("url", channel.Image.Url, true); WriteElement("link", channel.Image.Link, true); switch (rssVersion) { case RssVersion.RSS091: case RssVersion.RSS092: case RssVersion.RSS20: WriteElement("description", channel.Image.Description, false); WriteElement("width", channel.Image.Width, false); WriteElement("height", channel.Image.Height, false); break; } writer.WriteEndElement(); } switch (rssVersion) { case RssVersion.RSS091: case RssVersion.RSS092: case RssVersion.RSS20: WriteElement("language", channel.Language, rssVersion == RssVersion.RSS091); WriteElement("copyright", channel.Copyright, false); WriteElement("managingEditor", channel.ManagingEditor, false); WriteElement("webMaster", channel.WebMaster, false); WriteElement("pubDate", channel.PubDate, false); WriteElement("lastBuildDate", channel.LastBuildDate, false); if (channel.Docs != RssDefault.String) { WriteElement("docs", channel.Docs, false); } else { switch (rssVersion) { case RssVersion.RSS091: WriteElement("docs", "http://my.netscape.com/publish/formats/rss-spec-0.91.html", false); break; case RssVersion.RSS092: WriteElement("docs", "http://backend.userland.com/rss092", false); break; case RssVersion.RSS20: WriteElement("docs", "http://backend.userland.com/rss", false); break; } } WriteElement("rating", channel.Rating, false); string[] Days = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" }; for (int i = 0; i <= 6; i++) { if (channel.SkipDays[i]) { writer.WriteStartElement("skipDays"); for (int i2 = 0; i2 <= 6; i2++) { if (channel.SkipDays[i2]) { WriteElement("day", Days[i2], false); } } writer.WriteEndElement(); break; } } for (int i = 0; i <= 23; i++) { if (channel.SkipHours[i]) { writer.WriteStartElement("skipHours"); for (int i2 = 0; i2 <= 23; i2++) { if (channel.SkipHours[i2]) { WriteElement("hour", i2 + 1, false); } } writer.WriteEndElement(); break; } } break; } switch (rssVersion) { case RssVersion.RSS092: case RssVersion.RSS20: if (channel.Categories != null) { foreach (RssCategory category in channel.Categories) { if (category.Name != RssDefault.String) { writer.WriteStartElement("category"); WriteAttribute("domain", category.Domain, false); writer.WriteString(category.Name); writer.WriteEndElement(); } } } if (channel.Cloud != null) { writer.WriteStartElement("cloud"); WriteElement("domain", channel.Cloud.Domain, false); WriteElement("port", channel.Cloud.Port, false); WriteElement("path", channel.Cloud.Path, false); WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false); if (channel.Cloud.Protocol != RssCloudProtocol.Empty) { WriteElement("Protocol", channel.Cloud.Protocol, false); } writer.WriteEndElement(); } break; } if (rssVersion == RssVersion.RSS20) { if (channel.Generator != RssDefault.String) { WriteElement("generator", channel.Generator, false); } else { WriteElement("generator", "RSS.NET: http://www.rssdotnet.com/", false); } WriteElement("ttl", channel.TimeToLive, false); // RSS Modules foreach (RssModule rssModule in this._rssModules) { if (rssModule.IsBoundTo(channel.GetHashCode())) { foreach (RssModuleItem rssModuleItem in rssModule.ChannelExtensions) { if (rssModuleItem.SubElements.Count == 0) { WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text, rssModuleItem.IsRequired); } else { writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix); } } } } } if (channel.TextInput != null) { writer.WriteStartElement("textinput"); WriteElement("title", channel.TextInput.Title, true); WriteElement("description", channel.TextInput.Description, true); WriteElement("name", channel.TextInput.Name, true); WriteElement("link", channel.TextInput.Link, true); writer.WriteEndElement(); } foreach (RssItem item in channel.Items) { writeItem(item, channel.GetHashCode()); } writer.Flush(); }
static void Main(string[] args) { RssFeed r = new RssFeed(); r.Version = RssVersion.RSS20; RssItem ri1a = new RssItem(); ri1a.Author = "Test Author 1a"; ri1a.Title = "Test Title 1a"; ri1a.Description = "Test Description 1a"; ri1a.Link = new Uri("http://www.yourserver.com/"); ri1a.PubDate = DateTime.Now; RssItem ri1b = new RssItem(); ri1b.Author = "Test Author 1b"; ri1b.Title = "Test Title 1b"; ri1b.Description = "Test Description 1b"; ri1b.Link = new Uri("http://www.yourserver.com/"); ri1b.PubDate = DateTime.Now; RssChannel rc1 = new RssChannel(); rc1.Items.Add(ri1a); rc1.Items.Add(ri1b); rc1.Title = "Test Channel Title 1"; rc1.Description = "Test Channel Description 1"; rc1.Link = new Uri("http://www.yourserver.com/channel.html"); rc1.PubDate = DateTime.Now; r.Channels.Add(rc1); RssPhotoAlbumCategoryPhotoPeople pacpp = new RssPhotoAlbumCategoryPhotoPeople("John Doe"); RssPhotoAlbumCategoryPhoto pacp1 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 12, 0, 0)), "Test Photo Description 1", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=123"), pacpp); RssPhotoAlbumCategoryPhoto pacp2 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=124")); RssPhotoAlbumCategoryPhoto pacp3 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=125")); RssPhotoAlbumCategoryPhotos pacps = new RssPhotoAlbumCategoryPhotos(); pacps.Add(pacp1); pacps.Add(pacp2); RssPhotoAlbumCategory pac1 = new RssPhotoAlbumCategory("Test Photo Album Category 1", "Test Photo Album Category Description 1", DateTime.Now.Subtract(new TimeSpan(5, 10, 0, 0)), DateTime.Now, pacps); RssPhotoAlbumCategory pac2 = new RssPhotoAlbumCategory("Test Photo Album Category 2", "Test Photo Album Category Description 2", DateTime.Now.Subtract(new TimeSpan(9, 10, 0, 0)), DateTime.Now, pacp3); RssPhotoAlbumCategories pacs = new RssPhotoAlbumCategories(); pac1.BindTo(ri1a.GetHashCode()); pac2.BindTo(ri1b.GetHashCode()); pacs.Add(pac1); pacs.Add(pac2); RssPhotoAlbum pa = new RssPhotoAlbum(new Uri("http://your.web.server/PhotoAlbumWeb"), pacs); pa.BindTo(rc1.GetHashCode()); r.Modules.Add(pa); RssItem ri2 = new RssItem(); ri2.Author = "Test Author 2"; ri2.Title = "Test Title 2"; ri2.Description = "Test Description 2"; ri2.Link = new Uri("http://www.yourotherserver.com/"); ri2.PubDate = DateTime.Now; RssChannel rc2 = new RssChannel(); rc2.Items.Add(ri2); rc2.Title = "Test Channel Title 2"; rc2.Description = "Test Channel Description 2"; rc2.Link = new Uri("http://www.yourotherserver.com/channel.html"); rc2.PubDate = DateTime.Now; r.Channels.Add(rc2); r.Write("out.xml"); RssBlogChannel rbc = new RssBlogChannel(new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com")); }
private void writeChannel(RssChannel channel) { if (Writer == null) { throw new InvalidOperationException("RssWriter has been closed, and cannot be written to."); } if (channel == null) { throw new ArgumentNullException("Channel must be instanciated with data to be written."); } if (ChannelBegun) { Writer.WriteEndElement(); } else { ChannelBegun = true; } BeginDocument(); Writer.WriteStartElement("channel"); WriteElement("title", channel.Title, true); WriteElement("description", channel.Description, true); WriteElement("link", channel.Link, true); if (channel.Image != null) { Writer.WriteStartElement("image"); WriteElement("title", channel.Image.Title, true); WriteElement("url", channel.Image.Url, true); WriteElement("link", channel.Image.Link, true); WriteElement("description", channel.Image.Description, false); WriteElement("width", channel.Image.Width, false); WriteElement("height", channel.Image.Height, false); Writer.WriteEndElement(); } WriteElement("language", channel.Language, Version == RssVersion.RSS091); WriteElement("copyright", channel.Copyright, false); WriteElement("managingEditor", channel.ManagingEditor, false); WriteElement("webMaster", channel.WebMaster, false); WriteElement("pubDate", channel.PubDate, false); WriteElement("lastBuildDate", channel.LastBuildDate, false); if (channel.Docs != RssDefault.String) { WriteElement("docs", channel.Docs, false); } else { WriteElement("docs", "http://backend.userland.com/rss", false); } WriteElement("rating", channel.Rating, false); WriteSkipDays(channel); WriteSkipHours(channel); if (channel.Categories != null) { foreach (RssCategory category in channel.Categories) { if (category.Name != RssDefault.String) { Writer.WriteStartElement("category"); WriteAttribute("domain", category.Domain, false); Writer.WriteString(category.Name); Writer.WriteEndElement(); } } } if (channel.Cloud != null) { Writer.WriteStartElement("cloud"); WriteElement("domain", channel.Cloud.Domain, false); WriteElement("port", channel.Cloud.Port, false); WriteElement("path", channel.Cloud.Path, false); WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false); if (channel.Cloud.Protocol != RssCloudProtocol.Empty) { WriteElement("Protocol", channel.Cloud.Protocol, false); } Writer.WriteEndElement(); } if (channel.Generator != RssDefault.String) { WriteElement("generator", channel.Generator, false); } else { WriteElement("generator", "RSS.NET: http://rss-net.sf.net/", false); } WriteElement("ttl", channel.TimeToLive, false); // RSS Modules foreach (RssModule rssModule in this._rssModules) { if (rssModule.IsBoundTo(channel.GetHashCode())) { foreach (RssModuleItem rssModuleItem in rssModule.ChannelExtensions) { if (rssModuleItem.SubElements.Count == 0) { WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text, rssModuleItem.IsRequired); } else { writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix); } } } } if (channel.TextInput != null) { Writer.WriteStartElement("textinput"); WriteElement("title", channel.TextInput.Title, true); WriteElement("description", channel.TextInput.Description, true); WriteElement("name", channel.TextInput.Name, true); WriteElement("link", channel.TextInput.Link, true); Writer.WriteEndElement(); } foreach (RssItem item in channel.Items) { writeItem(item, channel.GetHashCode()); } Writer.Flush(); }