Validate XMLs against XSDs

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
peter_b
Chatterbox
Posts: 371
Joined: Tue Nov 12, 2013 2:05 am

Validate XMLs against XSDs

Post by peter_b »

This HowTo describes how to validate XML files, using XML Schema Definition (XSD) files, using "xmllint".

Here's the basic commandline:

Code: Select all

$ xmllint --noout --schema $XSD_FILE $XML_FILE


To make things more interesting, I'll use a somewhat real-world example of a METS Metadata XML export - cmmon in long-term preservation context.

Let's say we have the following set of files: Validating if the XML file (metadata_mets.xml), generated by a preservation system is actually a valid METS file, we use the proper schema definition (mets.xsd) and validate it using xmllint:

Code: Select all

$ xmllint --noout --schema mets.xsd metadata_mets.xml
If everything is fine, the result should be:
metadata_mets.xml validates
If not, you will receive information about what/where in the XML file does not validate against the given XSD.
Post Reply