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). Exporting a schema in SCM format makes it quicker to reload when the same schema is used again. It is also a format that is easier for programs to analyze, in comparison with raw XSD schema documents.
The simplest way to create an SCM file is from the command line, using the
com.saxonica.Validate
command with the -scmout
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 can be imported using the -scmin
option of the
com.saxonica.Validate
command. It can also be loaded programmatically using
the SchemaModelLoader
class. 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. In particular, it can be used when compiled queries
are run under this Configuration
.
Schema Component Models can also be imported and exported using the
importComponents()
and exportComponents()
methods of the SchemaManager
in the s9api
interface.
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.