Categories
Developer Community

New RSS Feed for Developer Fusion

Well, I’ve finally gotten around to publishing an RSS feed for the articles on Developer Fusion . You can get it here – http://www.developerfusion.com/rss/contentrss.aspx?type=articles&language=all .


For anyone who’s interested in the code behind it – I just wrote this simple helper class.

/// <summary>
/// Enables the generation of an RSS feed
/// </summary>
public class RSSFeedGenerator
{
    XmlTextWriter writer;
    public RSSFeedGenerator( System.IO.Stream stream, System.Text.Encoding encoding )
    {
        writer = new XmlTextWriter(stream, encoding);
        writer.Formatting = Formatting.Indented;
    }
    public RSSFeedGenerator( System.IO.TextWriter w )
    {
        writer = new XmlTextWriter(w);
        writer.Formatting = Formatting.Indented;
    }
    /// <summary>
    /// Writes the beginning of the RSS document
    /// </summary>
    public void WriteStartDocument()
    {
        writer.WriteStartDocument();
        //writer.WriteComment(“Generated by Developer Fusion RSS feed at ” + DateTime.Now.ToString(“r”));
        writer.WriteStartElement(“rss”);
        writer.WriteAttributeString(“version”,”2.0″);
    }
    /// <summary>
    /// Writes the end of the RSS document
    /// </summary>
    public void WriteEndDocument()
    {
        writer.WriteEndElement(); //rss
        writer.WriteEndDocument();
    }
    /// <summary>
    /// Closes this stream and the underlying stream
    /// </summary>
    public void Close()
    {
        writer.Flush();
        writer.Close();
    }
    /// <summary>
    /// Begins a new channel in the RSS document
    /// </summary>
    /// <param name=”title”></param>
    /// <param name=”link”></param>
    /// <param name=”description”></param>
    public void WriteStartChannel(string title, string link, string description, string copyright )
    {
        writer.WriteStartElement(“channel”);
        writer.WriteElementString(“title”,title);
        writer.WriteElementString(“link”,link);
        writer.WriteElementString(“description”,description);
        writer.WriteElementString(“language”,”en-gb”);
        writer.WriteElementString(“copyright”,copyright);
        writer.WriteElementString(“generator”,”Developer Fusion RSS Feed Generator v1.0″);
        writer.WriteElementString(“webMaster”,”James Crowley”);
        writer.WriteElementString(“lastBuildDate”,DateTime.Now.ToString(“r”));
        writer.WriteElementString(“ttl”,”20″);
       
    }
    /// <summary>
    /// Writes the end of a channel in the RSS document
    /// </summary>
    public void WriteEndChannel()
    {
        writer.WriteEndElement(); //channel
    }
    /// <summary>
    /// Writes an item to a channel in the RSS document
    /// </summary>
    /// <param name=”title”></param>
    /// <param name=”link”></param>
    /// <param name=”description”></param>
    /// <param name=”author”></param>
    /// <param name=”publishedDate”></param>
    /// <param name=”category”></param>
    public void WriteItem(string title, string link, string description, string author, DateTime publishedDate, string subject)
    {
        writer.WriteStartElement(“item”);
        writer.WriteElementString(“title”,title);
        writer.WriteElementString(“link”,link);
        writer.WriteElementString(“description”,description);
        writer.WriteElementString(“author”,author);
        writer.WriteElementString(“pubDate”,publishedDate.ToString(“r”));
        //writer.WriteElementString(“category”,category);
        writer.WriteElementString(“subject”,subject);
        writer.WriteEndElement();
    }
}


and then it was *really* simple to generate the RSS! 🙂

// set the content type
Page.Response.ContentType = “text/xml”;
// create a RSS feed generator for the output
RSSFeedGenerator gen = new RSSFeedGenerator(Page.Response.Output);
gen.WriteStartDocument();
gen.WriteStartChannel(“Developer Fusion RSS Feed”,
“http://www.developerfusion.com/”,
“Summary of the latest articles published on Developer Fusion”,
“Copyright © Developer Fusion Ltd, 1999-2004”);
// generate the items here
gen.WriteItem(“Some Great Article,”http://www.developerfusion.com/show/10/”,”description”,”James Crowley”,DateTime.Now, “ASP.NET”);
// clear up
gen.WriteEndChannel();
gen.WriteEndDocument();
gen.Close();

Oh – and if anyone can show me how to post this code correctly on these weblogs, then please drop me a line!

6 replies on “New RSS Feed for Developer Fusion”

With regard to your queston "if anyone can show me how to post this code correctly on these weblogs", I don”t know if your editor supports adding your own (x)html tags, but in stead of putting the code between &lt;CODE&gt;…&lt;/CODE&gt; tags I would recommend to try &lt;XMP&gt;…&lt;/XMP&gt;

surrounding tags in stead. These tags are meanth for "eXaMPle" code (I think it was introduced by Netscape first, then implemented in IE too). However, in that case, you MUST then type codes as they really are, that is: "&lt;" and not "&amp;lt;", because the browser will NOT html-encode these characters. And I don”t know if that will be compatible with the RSS file (which is XML, and does not like to see unencoded &lt; and &gt; signs…

Just try it;)

Oops, this comments editor doesn”t understand html-encoding either! Would it understand this: "<" ?

It does. So I try again:

With regard to your queston "if anyone can show me how to post this code correctly on these weblogs", I don”t know if your editor supports adding your own (x)html tags, but in stead of putting the code between <CODE>…</CODE> tags I would recommend to try <XMP>…</XMP> surrounding tags in stead. These tags are meanth for "eXaMPle" code (I think it was introduced by Netscape first, then implemented in IE too). However, in that case, you MUST then type codes as they really are, that is: "<" and not "&lt;", because the browser will NOT html-encode these characters. And I don”t know if that will be compatible with the RSS file (which is XML, and does not like to see unencoded < and > signs…

Hope this helps.

Well…does anybody have a real comment to the code itself ? No…ok. let me say that the class you wrote is great. I wonder whether there isnt any class provided be MS for that purpose. Do you anything about that ?

Thanks, sonu

Leave a Reply to http:// Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.