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:
An SCM file is much faster load than the corresponding source schema documents.
An SCM file is much easier for applications to process that the corresponding source documents: whether written in Java, XSLT, or XQuery, applications that need access to schema information can find it much more readily in an SCM document than in the source schema.
An SCM file may contain an embedded license key, enabling it to be used for validating source documents on a Saxon-EE configuration that does not have its own license.
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
An SCM file is accepted by most interfaces that allow a source XSD file to be supplied, for example:
-xsdoption of the command-line
load()method of the s9api
xsi:noNamespaceSchemaLocationattributes in an instance document (the SCM file contains components for multiple namespaces, and it should only be loaded once)
xsl:import-schemadeclaration in XSLT, or an
import schemadeclaration in XQuery.
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
exportComponents() methods of the SchemaManager in the s9api
An SCM file cannot be used as the target of
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
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.