lunedì 2 luglio 2007

The downlevel W3C html validator is smart enough to know which html content render to which browser, which is good. However there's a small flaw in the browser detection: the W3C html validator is detected as pre-DOM (and since it's not a real browser it logically is one of those), but that defeats the purpose of validating the output of a website.
Luckily it's quite easy to fix this issue. Just create a folder called App_Browsers in your website root and place a file called w3cvalidator.browser, containing the following code:

Browser capability file for the W3C validator
Sample User-Agent: "W3C_Validator/1.432.2.22"
<browser id="w3cValidator" parentid="Default">
<useragent match="^W3C_Validator">
<useragent match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*">
<capability value="w3cValidator" name="browser">
<capability value="${major}" name="majorversion">
<capability value="${minor}" name="minorversion">
<capability value="${version}" name="version">
<capability value="1.0" name="w3cdomversion">
<capability value="true" name="xml">
<capability value="System.Web.UI.HtmlTextWriter" name="tagWriter">

One small side note. Initially I was placing this file along with another .browser file that I use to render PNG images with transparences (will talk about this little gem in the future). That one was called All.browser and rendered the right code for all browsers, but somehow it prevented the use of the w3cvalidator.browser file. Merging those two files into one did the trick.