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.

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

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

The equivalent on the .NET platform is:

Validate [options]  source.xml  schema.xsd  

The options must come first, then the file names.

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

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

The options are as follows (in any order):

-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.


Schema check only. In this case, the source file name should be omitted. The program reads the supplied schema, checks it for internal consistency, reports any errors, and exits.


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


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 lax validation. This option has no effect when the -s option is also used. Lax validation validates elements only if there is an element declaration to validate them against, or if they have an xsi:type attribute.

-x classname

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. Normally this means that the Crimson parser included as standard in JDK 1.4 will be used. 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.


Allow 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.


Display command syntax


Identifies the source file to be validated. This argument is mandatory unless the -s option is present, in which case it must be omitted. The argument can be specified as "-" to read the source file from standard input.


Identifies the schema to be used for validation. This argument is mandatory if the -s option is present. In other cases it may be omitted, and the schema to be used for validation will then be located using the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes in the source document. The argument can be specified as "-" to read the schema from standard input.

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.