XHTML Validation Filter

Add "?vf-src=true" to the end of a URL that is mapped to the filter and you should see your source displayed with ValidationFilter.

How can I disable ValidationFilter in production?

Ensure your production url's are not in "enableOnHosts" in your web.xml

            <param-value>localhost,, dev.foobar.com, *.test.foobar.com </param-value>


If you are using Tomcat and you are paranoid then to your [tomcat-directory]/conf/web.xml add:


Under the <web-app> element near the top of the file on your production machines this will ensure that ValidationFilter never does anything.

Can I check all files even if they have no XHTML doctype specified?

If you want ValidationFilter to be aggressive and check everything is valid not just HTML pages with the XHTML DTD specified then add this init param (it's true by default).


Can the XHTML errors be suppressed sometimes?

Set the init parameter "displayOriginal" to true and the error message will be displayed optionally.


Can I use a different XML parser than the system default?

Yes, you can specify a custom XML parser (if you want to do this for your whole web application then specify it in the normal way in a system property with the key javax.xml.parsers.DocumentBuilderFactory), otherwise add the init-param below. Note, is this is not specified ValidationFilter will use the default XML parser.


Why doesn't ValidationFilter support HTMLx.x?

Because validating plain old HTML is rather difficult. The best thing to do is use W3C's validator.

Is ValidationFilter fast.

Yes pretty fast. But it is not recommended to have it enabled in poduction as it won't really help people using your site. It is a developers tool.

Why should I use XHTML and not plain old HTML?

Basically because XHTML is HTML based on XML. It means any old XML parser can do things with your content easily. Search engines (robots), translators, blind readers have a much easier time reading valid XHTML than old dirty HTML. XHTML is only good... when valid, otherwise it's useless. That is where ValidationFilter comes in. It will validate all your outgoing XHTML as you develop and show you errors so that you can fix them during development.

Better said at wdvl.com's Why use XHTML and Introduction to XHTML or w3schools.com's Learn XHTML or zvon.org's Excellent XHTML reference.