Click here to Skip to main content
15,867,962 members
Articles / Web Development / HTML

Web RSS Builder Part 1: Building Generic XML Data Source for ASP.NET and Silverlight

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
5 Nov 2010CPOL3 min read 23.3K   15  
A description of the open source Web RSS Builder

Introduction

Web RSS Builder is an open source application for managing RSS files using Web-based and Silverlight-based interfaces. This application is useful when you need to manage RSS files on the server using a web application.

The application is hosted on CodePlex at http://WebRSSBuilder.codeplex.com.

This is part 1 of a three-part post which will describe this application:

Why?

I started working on this when I was asked to adapt an open source Desktop-based application to manage RSS files, and since I was working on a big organization, I felt the need to move to a web application for many reasons:

  1. It will take a long time to get the feedback, and since no update mechanism is embedded in the software, you will need to reinstall it on each update, i.e. headache for the IT department.
  2. Employees will need access authority to files on the server, which is not really a good idea; security-wise.

Requirements

The application is quite simple! The requirements are:

  1. Keep a list of all the RSS files on a server
  2. Attach each file to a specific role
  3. Develop a web interface to manage RSS files

Application Architecture

The application will contain three main projects:

  1. The Core Project: This will contain the data binding classes responsible for representing and controlling RSS files.
  2. The ASP.NET Project: This will contain the ASP.NET Web application interface.
  3. The Silverlight Project: Actually they are two: client and server, this will contain the Silverlight application interface.

The Core Component

The application will use the Model-View-Controller (MVC) design pattern and its variations Model-View-ViewModel (MVVM) in Silverlight. The core component's main responsibility is to provide a generic data source for RSS files that will be used in ASP.NET and Silverlight.

Model

The Model classes for RSS files are:

  • RSSFeed: which represents the RSS file, RSS Feed implements INotifyPropertyChanged to notify binding object with any change in data, it also contains:
    1. Properties: such as Title, Category, etc.
    2. RSS Items
    3. c. Indexer
  • RSSItem: represents an RSS item which also implements INotifyPropertyChanged to notify the Feed object with any change in data, it contains:
    1. Properties: such as Author, Description, Pubdata

Controller

The Controller is the object responsible for reading and writing RSS XML files and since that could be done in different ways, the controller is abstracted in an interface IRSSFeedController. This interface defines two basic methods for Loading and Saving:

C#
namespace WebRSSBuilder.Core
{
    public interface IRSSFeedController
    {
        RSSFeed LoadRss(string FileURI);
        void SaveFeed(RSSFeed Feed); 
    }
}

The controller could be implemented in different ways:

  1. Using XML DOM
  2. Using LINQ to XML
  3. Using simple stream text
  4. And maybe others...

At this stage, I provided one implementation using LINQ to XML through the Class RSSFeedXLinqController. For those who are not familiar with LINQ to XML, I will describe that briefly.

This class contains in addition to the interface Load and Save methods, three helper methods:

  1. GetElement: takes an XElement and searches within it for a specific XML tag.
  2. GetAttribute: takes an XElement and searches within it for a specific XML attribute.
  3. GenerateChannel: takes a Feed file and generates an XElement for it, the code is self-descriptive, anyways if anybody has any question, please do ask.
C#
private string GetElement(XElement x, string ElementName)
{
   XElement Element = x.Element(ElementName);
   return (Element == null ? null : Element.Value.Trim());
}
private string GetAttribute(XElement x, string ElementName)
{
   string ElementValue = x.Element(channel).Attribute(ElementName).Value;
   return (ElementValue == null ? null : ElementValue.Trim());
} 
private XElement GenerateChannel(RSSFeed Feed)
{
    XElement Channel = new XElement("channel");
    #region Saving Properties
    if (Feed.Category != null)
         Channel.Add(new XElement("category", Feed.Category));
    if (Feed.CloudDomain != null)
     {
       Channel.Add(new XElement("cloud", new XAttribute("domain", Feed.CloudDomain),
                   new XAttribute("port", Feed.CloudPort),
                   new XAttribute("registerProcedure", Feed.CloudRegisterProcedure),
                   new XAttribute("protocol", Feed.CloudProtocol)
                   ));
      }
    if (Feed.Copyright != null)
       Channel.Add(new XElement("copyright", Feed.Copyright));
...

This class implements IRSSFeedController:

  1. LoadRss: This method loads the feed properties through GetElement, and loads the items through LoadItem.
  2. SaveFeed: This method generates the XLinq object using the GenerateChannel method.
C#
public RSSFeed LoadRss(string FileURI)
 {
   DateTime help;
   XElement root = XElement.Load(FileURI);
   RSSFeed Feed = new RSSFeed();
   XElement Channel = root.Element("channel");
   #region Loading properties
   Feed.FileName = FileURI;
   Feed.Title = GetElement(Channel, "title");
   ...
   #endregion
   IEnumerable<xelement> items = from el in Channel.Elements("item") select el;
   foreach (XElement item in items)
   {
     Feed.Items.Add(LoadItem(item));
   }
   return Feed;
}
private RSSItem LoadItem(XElement x)
{
  RSSItem item = new RSSItem();
  DateTime help;
  bool b;
  int i;
  item.Author = GetElement(x, "author");
  item.Category = GetElement(x, "category");
  item.Comments = GetElement(x, "comments");
  ...
  return item;
}

Next Article

In the next article, we will go through the ASP.NET application that will use what we described here to bind to an RSS data source.

Did You Like the Article?

If you did, please vote for it. :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
He is a Software developer and currently doing a Master's degree in Computer Science, his main fouces is .Net, ASP.Net, and Silverlight.

Comments and Discussions

 
-- There are no messages in this forum --