Xerces validator in command line
Tested with Xerces 2.6.2 - Jean-Marc Vanel
I hacked the sax.Counter sample shipped with Xerces to be able to
validate against an external Schema (not assigned in the XML instance
through
xmlSchemaLocation or xmlNoNamespaceSchemaLocation ). The source is here:
http://jmvanel.free.fr/xsd/Counter.java
The .class is also here in same directory. You can replace the original
Counter.java in $XERCES_HOME/samples/sax and compile it:
javac -classpath $XERCES_HOME/xercesImpl.jar:$XERCES_HOME/xmlParserAPIs.jar \
sax/Counter.java
or directly download the class from here:
http://jmvanel.free.fr/xsd/Counter.class
Then put in your $HOME/bin a script "xmlvalid" with this content :
java -classpath $XERCES_HOME/xercesImpl.jar:$XERCES_HOME/xmlParserAPIs.jar:$XERCES_HOME/samples sax.Counter $*
Use it this way:
xmlvalid -esl http://apache.org/cocoon/sitemap/2.0 ~/contrats/thomasson/sitemap.xsd sitemap.xmap
which means:
xmlvalid -esl Namespace1 URL_of_XSD1 \
Namespace2 URL_of_XSD2 URL_of_XML_instance
or for a no Namespace Schema :
xmlvalid -ennsl URL_of_XSD URL_of_XML_instance
For those who prefer a Windows .bat script, here it is:
java -classpath
%XERCES_HOME%/xercesImpl.jar;%XERCES_HOME%/xmlParserAPIs.jar;%XERCES_HOME%/samples
sax.Counter %*