Command Line XML Validation Against Schema XSD

Even though I do a ton of work with XML files, I don't use actual XML Schema documents very often. It seems like this is the case with most people who work with XML files. After spending some time working with schemas, it's not hard to see why. They are tedious and it is very easy to get by without having to use them. In day-to-day operation, they offer very little value. Especially considering the language is dense to start with and bulky to work with.

One plays where Schemas are very valuable is in testing software while it's still in development or when a change is being put in place. The language has a lot of potential for catching little errors that would otherwise be missed in high level test suites.

The impression I get is that a lot of other folks are running XML without really worrying about created Schemas. One of the main reasons is that I had to search for a couple hours to find a good command line tool that validates an XML document against a schema. The one I found and have so far been pleased with is Sun's "Multi-Schema XML Validator" known as "msv". The most recent version can be downloaded here. Note, if you are using a Mac with it's standard Java install, the latest version won't work out of the gate. Instead you can use the older version which is available here as

The core of msv is stored in a .jar file that is included with the zip. To run msv, the command would be something like:

< java -jar /path/to/msv.jar /path/to/schema.xsd /path/to/doc.xml

If the XML doc is valid, you'll see a message like:

< start parsing a grammar. < < validating /path/to/doc.xml < < the document is valid.

If there is an error, msv will report it and let you know what's wrong. Sometimes these can be a little cryptic, but when they are, they have enough info to get you started in the right direction.