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 faster to load than the corresponding source schema documents.
An SCM file is much easier for applications to process than 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, as
described in Validation from the command
line: use the -export
option.
Alternatively, an SCM file can be generated programmatically:
- From Java, use the
exportComponents()
method of the net.sf.saxon.s9api.SchemaManager class. - From C#, use the
ExportComponents()
method of the Saxon.Api.SchemaManager class. - From SaxonC, use the
exportSchema()
method of theSchemaValidator
class.
The export is unselective: it will output an SCM file 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:
The
-xsd
option of the command-lineValidate
commandThe
load()
method of net.sf.saxon.s9api.SchemaManager.The
Compile()
method of Saxon.Api.SchemaManager.The JAXP
SchemaFactory.newSchema()
method.The
registerSchemaFromFile()
method ofSchemaValidator
.The
xsi:schemaLocation
andxsi:noNamespaceSchemaLocation
attributes in an instance document (the SCM file contains components for multiple namespaces, and it should only be loaded once).An
xsl:import-schema
declaration in XSLT, or animport schema
declaration in XQuery.
A schema loaded in this way is then available for all tasks performed using the same
Configuration
, including validation of source documents and compiling of
schema-aware queries and stylesheets.
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, an 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.