More XML Lessons

2004 December 15
by Karen

More XML Lessons

I had a breakthrough last week involving XML. The usability of the
little orange XML button has been irritating me for some time and I
have been trying to figure out how to deal with it without redirecting
users to another page explaining RSS. The reason being that I want
people who know what RSS is, to be able to get the feed. I also don't
like the idea of cluttering the screen with extra links (if I don't
have to).

What I really want to do is add an XSL to my XML file that includes an
explanation of RSS. So if you go to rss.xml in your web browser you get
an attractive page that explains RSS and shows you the feed formatted
nicely. However, RSS adopters can still just get the feed. I'm seen
this done with Atom feeds and I like the way it looks. I've just had
issues with making it work. Particularly with my feed for this site
which is created by Radio. Today I figured out how to add what I want
with little fuss.

The
following code adds a stylesheet to an existing XML file on the fly.
The original XML file stays the same it is just that the stylesheet
gets added when you view it.
<%
set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.4.0")
xmlDoc.load (Server.MapPath("rss.xml"))
'add XSL file
set docXsl =
xmlDoc.createProcessingInstruction("xml-stylesheet", "type='text/xsl'
href='basic_display.xsl'")
xmldoc.insertBefore docXsl, xmldocnew.documentElement
Response.ContentType = "text/xml"
response.write xmldoc.xml
%>

Linked is the stylesheet which gets attached and transforms the feed into something readable. Feel free to look at or use the code.

Overall,
this works quite well, but not consistently across browsers (of
course). This is because XML parsers vary from browser to browser. Oh
well, in my opinion this is a dramatic improvement over the original
orange button, but only time will tell.

Comments are closed for this entry.