User Tools

Site Tools


technology:java:xml_schema_validator_2

Non-Java XML Schema Validator

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 xmllint.

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.

/home/cfreyer/public_html/data/pages/technology/java/xml_schema_validator_2.txt · Last modified: 2010/03/17 12:02 by Chris Freyer