<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="schema-processing" page="scm" subpage=""/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Importing and Exporting Schema Component Models</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Importing and Exporting Schema Component Models"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Importing and Exporting Schema Component Models</h1>
      <p>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.</p>
      <p>The simplest way to create an SCM file is from the command line, using the <code>com.saxonica.Validate</code>
command with the <code>-scmout</code> option. This is described <a class="bodylink" href="../schema-processing/commandline.xml">here</a>. Alternatively,
an SCM file can be generated programmatically using the <code>exportComponents()</code> method of the
<a class="bodylink"
            href="../javadoc/com/saxonica/config/EnterpriseConfiguration.html"><code>com.saxonica.config.EnterpriseConfiguration</code></a> 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 <code>Configuration</code>, other than built-in schema components.</p>
      <p>An SCM file can be imported using the <code>-scmin</code> option of the  <code>com.saxonica.Validate</code> command.
It can also be loaded programmatically using the <a class="bodylink" href="../javadoc/com/saxonica/schema/SchemaModelLoader.html"><code>SchemaModelLoader</code></a> class. For example:</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>
SchemaModelLoader loader = new SchemaModelLoader(config);
loader.load(new StreamSource(new File("input.scm")));
</code>
         </pre>
      </div>
      <p>A schema loaded in this way is then available for all tasks performed using this <code>Configuration</code>, 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 <code>Configuration</code>.</p>
      <p>Schema Component Models can also be imported and exported using the <code>importComponents()</code> and 
<code>exportComponents()</code> methods of the <code>SchemaManager</code> in the s9api interface.</p>
      <p>The structure of an SCM file is defined in the schema <code>scmschema.xsd</code> which is available
in the directory <code>samples/scm/</code> in the <code>saxon-resources</code> 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 <code>scmschema.scm</code> which contains the schema for SCM in SCM format.</p>
      <div class="boxed"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">The SCM file includes a representation of the finite state machines used to validate instances
against a complex type. This means that the FSM does not need to be regenerated when a schema is loaded
from an SCM file, which saves a lot of time. However, it also means that the SCM format is not currently
suitable as a target format for software-generated schemas. A variant of SCM in which the finite state
machines can be omitted may be provided in a future release.</div>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="min-and-maxoccurs.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>