Running Validation from the Command Line

The Java class com.saxonica.Validate allows you to validate a source XML document against a given schema, or simply to check a schema for internal correctness.

This command has been redesigned in Saxon 9.0, and is not backwards-compatible

To validate a source document, using the Java platform, write:

java  com.saxonica.Validate   [options]  source.xml...  

The equivalent on the .NET platform is:

Validate [options]  source.xml...  

Source files to be validated can be listed either using the -s option, or in any argument that is not prefixed with "-". This allows the standard wildcard expansion facilities of the shell interpreter to be used, for example *.xml validates all files in the current directory with extension "xml".

To check a schema for internal correctness, the command is:

[java com.saxonica.validate | Validate] -xsd:schema.xsd [other-options]

The options are as follows (in any order):


Sets upper limits on the values of minOccurs and maxOccurs allowed in a schema content model. High values of minOccurs and maxOccurs can cause the size of the compiled schema to grow dramatically, causing out-of-memory conditions. If the values used in the schema exceed these limits, Saxon will therefore approximate by generate a schema that does not strictly enforce the specified minOccurs and maxOccurs. The default limits are 100 and 250 respectively.

-r classname

Use the specified URIResolver to process all URIs. The URIResolver is a user-defined class, that implements the URIResolver interface defined in JAXP, whose function is to take a URI supplied as a string, and return a SAX InputSource. It is invoked to process URIs used in the doc() function, and (if -u is also specified) to process the URI of the source file provided on the command line.


Supplies a list of source documents to be validated. Each document is validated using the same options. The value is a list of filenames separated by semicolons. It is also possible to specify the names of source documents as arguments without any preceding option flag; in this case shell wildcards can be used. A filename can be specified as "-" to read the source document from standard input.


Loads a precompiled schema component model from the given file. The file should be generated in a previous run using the -scmout option. When this option is used, the -xsd option should not be present. Schemas loaded from an SCM file are assumed to be valid, without checking.


Makes a copy of the compiled schema (providing it is valid) as a schema component model to the specified XML file. This file will contain schema components corresponding to all the loaded schema documents. This option may be combined with other options, the SCM file is written after all document instance validation has been carried out.


Requests display of version and timing information to the standard error output. This also shows all the schema documents that have been loaded.


Requires that the outermost element of the instance being validated has the required name. This is written in Clark notation format "{uri}local".


Indicates that the name of the source document and schema document are supplied as URIs; otherwise they are taken as filenames, unless they start with "http:" or "file:", in which case they they are taken as URLs.


Invokes strict or lax validation (default is strict). Lax validation validates elements only if there is an element declaration to validate them against, or if they have an xsi:type attribute.


Requests use of the specified SAX parser for parsing the source file. The classname must be the fully-qualified name of a Java class that implements the org.xml.sax.XMLReader interface. In the absence of this argument, the standard JAXP facilities are used to locate an XML parser. Note that the XML parser performs the raw XML parsing only; Saxon always does the schema validation itself.


Apply XInclude processing to all input XML documents (both schema documents and instance documents). This currently only works when documents are parsed using the Xerces parser, which is the default in JDK 1.5 and later.


If set to 1.1, allows XML 1.1 and XML Namespaces 1.1 constructs. This option must be set if source documents using XML 1.1 are to be validated, or if the schema itself is an XML 1.1 document. This option causes types such as xs:Name, xs:QName, and xs:ID to use the XML 1.1 definitions of these constructs.


Supplies a list of schema documents to be used for validation. The value is a list of filenames separated by semicolons. If no source documents are supplied, the schema documents will be processed and any errors in the schema will be notified. This option must not be used when -scmin is specified. The option may be omitted, in which case the schema to be used for validation will be located using the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes in the source document. A filename can be specified as "-" to read the schema from standard input.


Display command syntax

The results of processing the schema, and of validating the source document against the schema, are written to the standard error output. Unless the -t option is used, successful processing of the source document and schema results in no output.