Previous Page Arrow Next Page Arrow

4.11 Importing and including schemas

If an XSD schema becomes too large, it can be split in several smaller pieces. The pieces are assembled into a global schema by means of an XSD <import>  or <include> directive. This feature also makes it possible to share resource kind definitions across several contracts. The shared definitions are placed in a separate schema resource which is imported by several contract schemas.

For example, the global CRM contract imports a “common” schema as follows:

<xs:schema xmlns:sc="http://schemas.sage.com/sc/2009" xmlns="http://schemas.sage.com/crmErp/2008" 
  xmlns:sme="http://schemas.sage.com/sdata/sme/2007" elementFormDefault="qualified" 
  targetNamespace="http://schemas.sage.com/crmErp/2008" id="crmErp" xmlns:xs="http://www.w3.org/2001/XMLSchema">
**  <xs:import schemaLocation="$schema/common" namespace="http://schemas.sage.com/sc/2009"/>
**
  <xs:element sme:role="resourceKind" sme:pluralName="tradingAccounts" sme:compliance="must" sme:canGet="true" sme:canPut="true" 
    sme:canPost="true" sme:canDelete="true" sme:isSyncSource="true" sme:isSyncTarget="true" name="tradingAccount" type="tradingAccount--type"/>
  <!-- more element and type definitions -->
</xs/schema>

If the imported schema is intended to be shared, as in the example above, it should have its own namespace and it should be imported with an <import> directive, as in the example above.

If, on the other hand, the smaller schema is only a fragment of the larger schema and is not intended to be shared, then it should be included with an <include> directive. The previous example could be modified to include its resource kind definitions from schema fragments, as follows:

<xs:schema xmlns:sc="http://schemas.sage.com/sc/2009" xmlns="http://schemas.sage.com/crmErp/2008" 
  xmlns:sme="http://schemas.sage.com/sdata/sme/2007" elementFormDefault="qualified" 
  targetNamespace="http://schemas.sage.com/crmErp/2008" id="crmErp" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation="$schema/common" namespace="http://schemas.sage.com/sc/2009"/>
**  <xs:include schemaLocation="$schema/tradingAccount"/>**
**  <xs:include schemaLocation="$schema/contact"/>**
**  <xs:include schemaLocation="$schema/contactGroup"/>
**  <!-- more RK include directives -->
</xs/schema>
SData providers MAY use this feature for large schemas

Previous Page Arrow Next Page Arrow