Validate XML to XSD with XMLLINT on CLI

I was looking for a nice tool to validate my XML messages against an XML Schema, when I ran into this command where you can really easily validate on the command line. That’s really cool since we’re becoming CLI ninjas anyway!
Update: This also works on Windows with this little gem.
The command is as follows:

xmllint --noout --schema schema.xsd ./message.xml

Which delivered the following output:

joris@jorislatitude:~/workspaces/_examples/XSD$ xmllint --noout --schema sample_schema.xsd ./messageone.xml
./messageone.xml:2: element S_UNB: Schemas validity error : Element 'S_UNB': This element is not expected. Expected is ( INSDES ).
./messageone.xml fails to validate

As shown in above message, my example failed to validate, which is what I suspected, but now I can send my integration partner a better and really precise explanation! As said above: Awesomeness! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.