Page 1 of 1

Validate XMLs against XSDs

Posted: Sat Jul 23, 2016 11:16 pm
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.