Public Release of ItSoftware.Syndication

  • .NET
  • Published: 2014-09-04 12:18:56 +00:00

Back in 2004 I created a syndication library for consuming and creating RSS/RDF/ATOM feeds. This library has been lying around for many years and I finally decided to make it public by making it downloadable from my homepage

This blog post will show some code examples and explain a little about how to use the library.

The first thing to show is how to create an RSS feed. I will not show how to create RDF or ATOM feeds because they follow the same procedure albeit other classes, and if you understand RSS you will understand the creation of RDF and ATOM as well. Note however that RSS/RDF and ATOM lie in their own namespaces.

In the following example, note that we use namespace extensions to the RSS feed using the SyndicationModule and SyndicationModuleCollection objects.


Rss rss = new Rss();
rss.Channel.Category.Add(new RssCategory(".NET"));
rss.Channel.Cloud = new RssCloud("www.ikjetil.no", "80", "path", "registerProcedure", "soap");
rss.Channel.Copyright = "Copyright (c) Kjetil Kristoffer Solberg";
rss.Channel.Description = "Description here.";
rss.Channel.Generator = "ItSoftware.Syndication";
rss.Channel.Language = "English";
rss.Channel.PubDate = RssDateTime.ToString(DateTime.Now, new TimeSpan(1, 0, 0));
rss.Channel.Title = "Showcase RSS feed.";
rss.Channel.Description = "RSS Channel Description.";
rss.Channel.Link = "http://www.itsoftware.no";

RssItem item = new RssItem();
rss.Channel.Items.Add(item);

item.Title = "A blog about a C# LINQ Provider";
item.PubDate = new RssDateTime(DateTime.Now, new TimeSpan(1, 0, 0)).ToString();
item.Link = "http://www.mylinkdomain.domain/rss.aspx?T=123";
item.Description = "I've just created a C# linq provider...";
item.Author = "Kjetil Kristoffer Solberg";
item.Category = new RssCategoryCollection();
item.Category.Add(new RssCategory(".NET"));
item.Category.Add(new RssCategory("C#"));
item.Category.Add(new RssCategory("LINQ"));
item.Comments = "http://www.mylinkdomain.domain/rss.aspx?T123#WhatDoYouThink";
item.GUID = new RssGuid(Guid.NewGuid().ToString(),"true");

item.Modules = new ItSoftware.Syndication.SyndicationModuleCollection();

SyndicationModule moduleCommentRss = item.Modules.Add( new SyndicationModule("wfw", "http://wellformedweb.org/CommentAPI/", SyndicationModuleNamespacePosition.DocumentElement));

SyndicationModuleElement moduleElementCommentRss = new SyndicationModuleElement("commentRss", "http://www.mydomain.domain/rss.aspx?T=123&C=1",
SyndicationModuleElementValueType.InnerText);
moduleCommentRss.Elements.Add(moduleElementCommentRss);

SyndicationModule moduleComments = item.Modules.Add( new SyndicationModule("slash", "http://purl.org/rss/1.0/modules/slash/", SyndicationModuleNamespacePosition.DocumentElement));
            
SyndicationModuleElement moduleElementComments = new SyndicationModuleElement("comments", "1", SyndicationModuleElementValueType.InnerText);
moduleComments.Elements.Add(moduleElementComments);

string rssXml = rss.Save(RssVersion.RSS_2_0_1, "utf-8").OuterXml;

To consume RSS/RDF and ATOM feeds you just do the following. Note that the uri could be a local file uri or http/ftp uri.


try
{
    SyndicationBase sb = Syndication.Load(new    Uri("http://www.ikjetil.no/Home/RssFeed/1?type=rss"));
                  
    if (sb is Rss)
    {
        // We have a RSS feed. Consume rss object.
        Rss rss = sb as Rss;
    }
    else if (sb is Rdf)
    {
        // We have a RDF feed. Consume rdf object.
        Rdf rdf = sb as Rdf;
    }
    else if (sb is Atom)
    {
        // We have an ATOM feed. Consume ATOM object.
        Atom atom = sb as Atom;
    }
}
catch (System.Net.WebException )
{
    // Invalid http/ftp uri
    throw;
}
catch ( SyndicationFormatInvalidException )
{
    // Invalid syndication format
    throw;
}

The next sample shows a simple F# console application that retrieves the current weather and prints it to the console


namespace WeatherHaugesund

open System
open System.Net
open ItSoftware.Syndication
open ItSoftware.Syndication.Rss

module ModuleMain =
 []
 let main(args : string[]) =
  let url = "http://www.yr.no/sted/Norge/Rogaland/Haugesund/Haugesund/varsel.rss"
  let sb : SyndicationBase = Syndication.Load(new Uri(url))
  let rss : Rss = sb :?> Rss
  printf "\n\n## Today ##\n%s\n\n" rss.Channel.Items.[0].Description
  0

These three examples should be all that you need to understand how to create and consume syndication feeds.

Note that you could also load the syndication feed from a string using the Syndication.LoadSyndication method.


Comments

Carl Kennedy

2017-03-28 13:26:59

Cool ;)

shruti

2018-07-17 10:37:08

I am really glad that I chose them for my desired work and problem because they have given me the results out of this world! Simply magnificent! Suggested to all!

reppors.com

2018-09-11 06:41:05

Excellent Blog! I have been impressed by your thoughts and the way you

Online Slots Real Money

2018-10-12 07:29:44

Hi I was searching for the blogs for many times, now I have reached at the right place.

Purple Heart Donation

2018-10-17 07:00:35

Every week-end I used to pay a fast visit this site, because I’d like enjoyment, because this web site conations certainly fussy material.

tiles

2018-10-18 10:49:15

I’m impressed with the special and informative contents that you just offer in such short timing.

seo services

2018-10-19 11:17:32

These are actually wonderful some ideas in the blog. You have touched good quality points here. In whatever way continue writing.

locksmith in arlington tx

2018-10-24 06:31:25

I suppose I've selected an unbelievable and interesting blog.

Thank you so much for such a great blog.

whizzy4you

2018-11-10 06:04:27

If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job.

Annabelle

2018-11-12 05:47:45

If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job.

Add comment

(no html)
(optional)
(optional)