Importing and Exporting Schema Component Models

Saxon provides the ability to export or import a compiled schema. The export format is an XML file, known as an SCM file (for schema component model). Using SCM files has three benefits:

The simplest way to create an SCM file is from the command line, using the com.saxonica.Validate command with the -export option. This is described in Running Validation from the Command Line. Alternatively, an SCM file can be generated programmatically using the exportComponents() method of the com.saxonica.config.EnterpriseConfiguration class, which is described in the JavaDoc. The serializer is unselective: it will output an SCM containing all the schema components that have been loaded into the Configuration, other than built-in schema components.

An SCM file is accepted by most interfaces that allow a source XSD file to be supplied, for example:

A schema loaded in this way is then available for all tasks performed using this Configuration, including validation of source documents and compiling of schema-aware queries and stylesheets.

Schema Component Models can also be imported and exported using the importComponents() and exportComponents() methods of the SchemaManager in the s9api interface.

An SCM file cannot be used as the target of xs:include, xs:import, xs:redefine, or xs:override declarations within a schema document. An SCM file represents a complete schema, not an individual module.

The schema components within an SCM file are sealed. This means it is not possible to change their effective meaning by adding new members to substitution groups, or deriving new types by extension. The components within an SCM file may be referenced from other components (loaded from a normal XSD document): for example types within an SCM file may be referred to from new element declarations. However, and SCM file will always be self-contained: it cannot contain external references to components loaded from elsewhere. It is possible to load two SCM files only if their components are non-overlapping, and neither refers to components in the other.

If the configuration used to generate an SCM file is licensed with a developer master key, then any exported SCM file will include an embedded license allowing it to be loaded and used for validation on a Saxon-EE configuration that does not have its own license. An SCM file containing an embedded license is protected from modification by checksums and digital signatures.

The structure of an SCM file is defined in the schema scmschema.xsd which is available in the directory samples/scm/ in the saxon-resources download file. This is annotated to explain the mappings between elements and attributes in the SCM file and components and properties as defined in the W3C XML Schema Specification. The same directory contains a file scmschema.scm which contains the schema for SCM in SCM format.