XHTML Strict Validation

I often use a XHTML Strict doctype on my websites and try to get them 100% valid every time (and I also put a link to the w3 validator service on each page). However, even though I do this the validator service often complains that my code isn't valid even though I know it is. The reason for this is that ASP.NET sees the request from w3 as coming from a "down-level" browser and as such sends different (and invalid for this doctype) XHMTL.

To get around this problem, I use a .browser file specifically for this service. To add it to your project you need to create an ASP.NET folder in your project called "App_Browsers". Then, inside that folder create a file named"w3cvalidator.browser" and add the following code:


Browser capability file for the w3c validator 
sample UA: "W3C_Validator/1.305.2.148 libwww-perl/5.803" 

    <browser id="w3cValidator" parentID="default"> 

            <userAgent match="^W3C_Validator" /> 
            <userAgent match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*" /> 

             <capability name="browser" value="w3cValidator" /> 
             <capability name="majorversion" value="${major}" /> 
             <capability name="minorversion" value="${minor}" /> 
             <capability name="version" value="${version}" /> 
             <capability name="w3cdomversion" value="1.0" /> 
             <capability name="xml" value="true" /> 
             <capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" /> 



Now, when the w3 service requests your page, it won't be treated as a low level browser and the correct HTML will be rendered so that your page will validate (assuming you haven't made any errors!).


Comments have been disabled for this content.