Importing and Exporting Schema Component Models

From version 9.0, 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 XSDL 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 here. Alternatively, an SCM file can be generated programmatically using the class com.saxonica.schema.SchemaModelSerializer, 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:

SchemaModelLoader loader = new SchemaModelLoader(config);
loader.load(new StreamSource(new File("input.scm")));

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.