I was perusing a back issue of Gunderloy's Daily Grind and found an article by Peter Freitag about a neat idea -- applying a CSS style sheet to your RSS feed. Raw RSS feeds look all XML-ish in the browser, but you can link the feed to a style sheet and then it can look nice(r). All you need to do is add a line like this:
<?xml version="1.0" ?>(Well, and there is the small matter of creating the style sheet -- Freitag illustrates that, too.)
<?xml-stylesheet type="text/css" href="http://you.com/rss.css" ?>
This sounded like fun. I added one to my comments feed (example), which was easy, because I keep the feed's XML skeleton in a text file, as described before.
I then turned my attention to the main feed. I implemented that way back when as a Web service (.asmx). I read a skeleton for that, too, and then fill in the
<rss> element and children with a bunch of tedious XmlElement-ing.
But I could not get the feed to include the style sheet link. I checked that the skeleton was indeed being read from the file, as expected, but somehow the
<?xml-stylesheet ?> element was just never getting in there.
It took me some time to realize that my skeletal
<?xml version="1.0" ?> element wasn't getting in there, either. The element was showing up -- or a version of the element was -- but it wasn't being put there by me. Hmmm. Hmmm.
Aha. I figured out that although I was supplying the
<rss> guts, the whole XML stream was actually, really being produced by the Web service. As in, the stream being sent to the browser was all the result of SOAP magic, and in the transformation to and from SOAP, the Web service paid no nevermind to anything outside the actual
<rss> content I was sending.
Slightly to my surprise, I found an article by "cmumford" on CodeProject.com that explained this and illustrated the solution. As he says: "Unfortunately, this involves serializing the object to a stream, deserializing it into a
XmlDocument, and then reserializing it after first attaching the processing directive."
Oh. Well, that's not going to happen. So one of these days, in my copious spare time, I guess I'll rewrite the main feed to be a handler instead of a Web service, which will give me direct control over what gets sent down the wire. And when I get around to that, keep your eye out for a much prettier feed.