Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Schemas

Using Other Namespaces

The include element allows you to reference and use schema components from external namespaces so that you do not have to redefine elements in every schema that requires the same existing content model or data type. It is possible to create new schemas that borrow or leverage from existing schemas.

Example

The following example shows the definitions and declarations from the humanresources.xsd schema are available to the containing schema through the use of the include element.

<xs:schema 
   xmlns="http://www.w3.org/2001/XMLSchema"
   xmlns:xs="http://www.w3.org/2001/XMLSchema-datatypes"
   targetNamespace="http://www.example.com">
</xs:schema>

<xs:include xmlns:myschema="http://www.myschema.com/humanresources.xsd" />

Alternatively, if you want to merge data from documents marked up according to two schemas, you could create a schema that would validate a new XML document (XML document instances). In the instance of a document marked up according to this schema, you only need to declare this schema (not the included schema).

Multiple Schemas

Multiple schemas from the same target namespace can be nested. This is useful if you want to create new XML documents based on data coming from several sources.

Example

The following example shows a schema for cookbooks that includes the content models from the recipebooks schema. The recipebooks schema describes content models for desserts and wines.

<xs:schema 
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/schemas/cookbooks">
<xs:import schemaLocation=http://www.example.com/schemas/recipebooks.xsd />

   <xs:element name="catalog" type="catalogType" />
   <xs:complexType name="catalogType">
      <xs:sequence>
         <xs:element name="desserts" type="cookbooks:dessertsType" />
         <xs:element name="wines" type="cookbooks:winesType" />
      </xs:sequence>
   <xs:attribute name="myISBN" type="cookbooks:ISBN" />
   </xs:complexType>
</xs:schema>

See Also

Using Namespaces in Schemas