New Feed Handlers
As part of my upgrade to .NET 3.5 all the feed handlers broke. The obvious thing to do was to fix the problems in the RssToolkit; however, as part of that process I decided to quickly see if I could just write some XML Linq to generate the feeds. It was pretty small learning curve, but the results were much better than I expected.
I've decided to give up fixing the RssToolkit and use my own XML Linq code. The great thing about this it that my goal of having a complete blogging platform in less that 2 KLOC is getting even closer.
The one really interesting (and annoying) part of the X-DOM is that you can't subclass any of the interesting objects (i.e. XElement). I wanted to write something to handle malformed XML (with some XDocumentFragment features) with an XElement subclass -- but it can't be subclassed! I wonder if the attempt to make a really easy to use and simple object model really needs to prevent subclassing to be successful?
Here's the interesting part of the Rss handler:
IBlogDatabase bdb = ServiceActivator<IBlogDatabase>.GetObject();
BlogDataSet tds = bdb.SelectPostsForRssFeed(MaxPostsForFeed);
XNamespace atom = "http://www.w3.org/2005/Atom";
XNamespace content = "http://purl.org/rss/1.0/modules/content/";
XNamespace dc = "http://purl.org/dc/elements/1.1/";
DateTime dt = (from row in tds.Posts select row.PostDate).Max();
XElement items =
new XElement("rss", new XAttribute("version", "2.0"),
new XAttribute(XNamespace.Xmlns + "atom", atom),
new XAttribute(XNamespace.Xmlns + "content", content),
new XAttribute(XNamespace.Xmlns + "dc", dc),
new XComment("Generated " + DateTime.Now.ToString("r")),
new XElement("channel",
new XElement("title", tds.Configuration.BlogTitle),
new XElement("description", tds.Configuration.BlogDescription),
new XElement("generator", "Scott's Blog Software"),
new XElement(dc + "creator", tds.Configuration.BlogOwner),
new XElement("pubDate", DateTime.Now.ToString("r")),
new XElement("lastBuildDate", dt.ToString("r")),
new XElement("managingEditor", tds.Configuration.BlogOwnerEmail),
new XElement("webMaster", tds.Configuration.BlogWebMasterEmail),
new XElement("docs", "http://www.rssboard.org/rss-specification"),
new XElement("language", "en-us"),
new XElement("link",
ResolveSiteHandler("~/FeedHandlerRss.ashx")"),
new XElement(atom + "link",
new XAttribute("href", ResolveSiteHandler("~/FeedHandlerRss.ashx")),
new XAttribute("rel", "self"),
new XAttribute("type", "application/rss+xml")),
from row in tds.Posts
orderby row.PostDate descending
select
new XElement("item",
new XElement("title", row.Title),
new XElement("pubDate", row.PostDate.ToString("r")),
new XElement("link", MakePostLink(row)),
new XElement("guid",
new XAttribute("isPermaLink", "true"), MakePostLink(row)),
new XElement("description", new XCData(GetPostExerpt(row))),
new XElement(content + "encoded", new XCData(GetPostExerpt(row)))
)
)
);
There are no comments.