Validation from C#

The Saxon.Api interface allows schemas to be loaded into a Processor, and then to be used for validating instances, or for schema-aware XSLT and XQuery processing.

The main steps are:

  1. Create a Processor and use its Processor.SchemaManager property to get a SchemaManager.

  2. If required, set options on the SchemaManager to control the way in which schema documents will be loaded.

  3. Load a schema document by calling one of the Compile() methods, which allow the input to be supplied in a variety of forms (for example, a Stream, a TextReader, or a Uri). The resulting schema is available to all applications run within the containing Processor.

  4. To validate an instance document, call the NewSchemaValidator() method on the SchemaManager object. This returns a SchemaValidator.

  5. Set options on the SchemaValidator to control the way in which a particular validation episode is performed, and then invoke one of its Validate() methods to validate an instance document.

Note that additional schemas referenced from the xsi:schemaLocation attributes within the source documents will be loaded as necessary, unless the SchemaValidator.UseXsiSchemaLocation property is set to false. By default a target namespace is ignored if there is already a loaded schema for that namespace; Saxon makes no attempt to load multiple schemas for the same namespace and check them for consistency. This behavior can be changed using the configuration option MULTIPLE_SCHEMA_IMPORTS.

Although the API is defined in such a way that a SchemaValidator is created for a particular SchemaManager, in the Saxon implementation the schema components that are available to the validator are not only the components within that schema, but all the components that form part of any schema registered with the Processor (or indeed, with the underlying Configuration).