Our website uses the Apache Velocity template language. Our Content Management System already checks any generated XML documents for well-formedness. We\'ve been asked to
There is a tool distributed with Velocity called TemplateTool, which dumps all the references and it can be used to validate the syntax of the template.
However, you must have the context setup correctly to verify any template. So the best verification is to write your own tool with your own context.
In December 2010 someone published a tool for validating Velocity. I tried it out and it works fine. It uses Velocity 1.6.4, but maybe that can be swapped out for a different version if needed.
http://code.google.com/p/velocity-validator/
To catch Velocity syntax errors, your approach is probably the best.
However, it will ignore invalid macro arguments and non-existent references. In Velocity 1.6 there is a strict mode that you can set which will throw an exception for bad macro parameters (e.g. the wrong number) or for bad references (e.g. $abc.badMethod() ). This assumes you are populating the context of the templates used in your testing tool the same as when the templates are used in production.