Friday 12 June 2009

Sitecore XHTML Validation - Attribute "name" exists, but can not be used for this element

If using XHTML 1.0 Strict and the site doesn't validate with the error "Attribute "name" exists, but can not be used for this element" See my previous post, check that you have added the following line into the web config in system.web
<xhtmlConformance mode="Strict" />

If you have done the above and you site if now valdiating locally, but not when using the w3c validator, this is because the w3c service uses a down level browser and the HTML that is generated doesn't comply to the standard that the DOCTYPE needs.

To solve this problem, you need to add a new .browser file in the App_Browsers directory. Just create a new file called w3cvalidator.browser and copy in the following code:
<browsers>  
  <!--  Browser capability file for the w3c validator  
        sample UA: "W3C_Validator/1.305.2.148 libwww-perl/5.803"  
  -->  
  <browser id="w3cValidator" parentID="default">  
    <identification>  
      <userAgent match="^W3C_Validator" />  
    </identification>  
  
    <capture>  
      <userAgent match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*" />  
    </capture>  
  
    <capabilities>  
      <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" />  
    </capabilities>  
  </browser>  
</browsers>
If adding the above file is still causing a problem, this will be related to that ASP.NET doesn't pick up newly added .browser files if the App_Browsers folder already contain at least one such file, even after the restarting IIS.

The workaround for this:
  1. Add the "w3cvalidator.browser" file to the App_Browsers directory.
  2. Move all the files from the App_Browsers.
  3. Request any site page so that ASP.NET application will be started(with the empty App_Browsers).
  4. Return all the moved files back to the App_Browsers directory.
  5. Try to validate the page via the W3C validator.

No comments: