In a previous article I have discussed how to create an RSS feed for a MCMS site.
So the next logical step is to discuss how a RSS feed can be agregated in a MCMS site - and it should be possible that content authors can configure the Feed Url and other parameters while authoring the site.
To ensure this we will create a MCMS RSS Agregator custom placeholder control.
Creating Authoring and Presentation Child Controls
The placeholder control needs to render different child controls during authoring time and during presentation time: During authoring the author should be able to configure the aggregated feed and in presentation time the information retrieved from the configured feed should be rendered in the configured way.
Let's first focus on the authoring time controls. I choosed the following configuration options for the control:
- the Feed URL (ok, this is obvious)
- the maximum number of articles to render (some feed can give you hundrets of articles....)
- option to render a link to to open the full article in a new browser window
- option to render the description text (otherwise only the headline will be shown)
- option to render the publishing date for all articles (if this information isincluded in the feed)
- option to render the author for all articles (if this information is included in the feed)
To give the author these configuration options we render TextBox, CheckBox and DropDownList controls. The placeholder control will utilize an XmlPlaceholder object to store the configuration information.
Now after we have created the authoring time controls we need to render the presentation time controls - but this is a quite simple job as we will use a Literal control to hold this data.
Implementing the Save Placeholder Content methods
As indicated before we will store the configuration information for the placeholder control inside a XmlPlaceholder object. To do this we need to wrap the configuration information inside a XmlStructure before saving this structure inside the bound XmlPlaceholder object.
Implementing the Load Placeholder Content methods for Authoring and Presentation mode
The first step is to remove the XML wrapper from the content in the XmlPlaceholder. After this we can use this content and either add the content directly to the Child controls (Authoring Mode) or to do run an HttpRequest against the configurerd Feed URL and create the desired html based on the returned feed information and the configuration information from the XmlPlaceholder object.
First I tried to use an XML/XSLT transformation to generate the html directly but due to the fact that I found that the different RSS feeds use different schemas to provide the same information. I finally ended up by directly parsing the XML stream and generating the Html manually. If someone has more experience with XML/XSLT and can provide a transformation XSLT file which will work with all kind of RSS feeds: please send it to me and I will adjust my placeholder control.
My small RSS-XML parser looks for the following XML tags to identify the different elements in the feed:
- Channel - this will contain sub tags with information about the feed.
- Item - this tag is used to hold information about one single article.
- Title - depending on the context this tag is used to wrap the feed or article title.
- Link - depending on the context this tag is used to wrap the link to the feed or to the article.
- Description - depending on the context this tag is used to wrap the feed or article description text.
- PubDate - this tag is used in some but not all RSS feeds to wrap the article publishing date.
- DC:Creator - this tag is used in some but not all RSS feeds to wrap the information about the author of the article.
- Author - same as the previous. Some but not all RSS feeds use this tag rather than the DC:Creator.
I tested this parser with around 50 feeds and it worked fine with all of them.
Here are some screenprints on how the controls works:
I have uploaded the control to GotDotNet.