1. Original Entry + Comments2. Write a Comment3. Preview Comment
New comments for this entry are disabled.


June 29, 2006  |  Stylin' with SOAP  |  5162 hit(s)

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" ?>
<?xml-stylesheet type="text/css" href="http://you.com/rss.css" ?>
<rss>
...
</rss>
(Well, and there is the small matter of creating the style sheet -- Freitag illustrates that, too.)

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.[1]

I then turned my attention to the main feed. I implemented that way back when as a Web service (.asmx).[2] 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.


[1] Naturally -- oh, how so very surprising -- IE and Firefox differ in support for applying CSS to XML tags with namespaces e.g. <dc:creator>. Firefox supports the proposed new syntax; IE6 does not. (AFAIK) Firefox will in fact ignore the namespace if you don't provide a URL and will apply CSS rules to tags as if they didn't have a namespace. I haven't tested any of this on IE7.

[2] Which I'll blame on Chris Anderson, whose BlogX I used as my very first model for creating this blog. :-)