Xml but not XHtml

Published on May 9, 2006

I finally got to the bottom of something that has been bothering me for a while. I generate my company website using a bunch of Xml files and an XSLT stylesheet. I have a small C# app that traverses a project file and builds all the pages. I recently upgraded the C# app from the 1.1 framework to 2.0. In doing so I was forced to change from using XslTransform to XslCompiledTransform which apparently has a different XSLT processing engine. The result was all of my web site pages were a mess. I was perplexed.

After much anguish I found the reason for the mess is that some tags that were previously being rendered as <div></div> were now being rendered as <div />. Weird I thought. Those two constructs are identical, no?

It seems that buried in the depths of the W3C XHtml spec it says that only tags that are supposed to be empty e.g. img should use the self-closing syntax. The rest should always use the seperate closing tag.

Thankfully some kind soul had posted some source code on one of MS's forums that creates a slightly enhanced version of XmlTextWriter that does a very nice job of creating the necessary ending tags.

My web pages are beautiful again, now I just have update the content!