Validating XML documents without Java has its advantages. Java has a high startup overhead. So validating documents with java inside a shell script can be really painful. Fortunately, there is
I created the shell script below for use inside other scripts. I
cd into a directory (the root of my web app) and run it. It finds all the XML files and checks them to see if they are valid XML. The return code on a VALID document is zero, but it is a positive integer when there are errors.
# Chris Freyer # October 21, 2009 # #! /bin/bash for f in `find . -name "*.xml"`; do xmllint --nowarning --noout --valid $f rc=$? if [ $rc -gt 0 ]; then echo RC on $f was $rc fi done
This has helped me find XML documents whose elements are out of sequence, or missing. It will also pinpoint the point at which XML documents are malformed.
For more details, visit the xmllint home page.