Name

xs:include

Synopsis

<xs:include
  id = "ID"
  schemaLocation = "anyURI">
  <!-- (annotation?) -->
</xs:include>

The top-level xs:include element is used to divide a schema into multiple separate documents. The schemaLocation attribute contains a relative or absolute URI pointing to the schema document to include. It differs from xs:import in that all included files describe the same target namespace.

There is no limit to inclusion depth. Schema A can include schema B, which itself includes schema C and schema D. In such a case, schema A can use definitions and declarations from all four documents. Even recursion (schema A includes schema B, which includes schema A) is not prohibited, although it is strongly discouraged. Instance documents would refer only to the top-level schema A in their xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute.

Validation is performed after all includes are resolved. If there are any conflicts between the including schema and an included schema—for instance, one schema declares that the FullName element has a simple type, and another declares that the FullName element has a complex type—then the schema is in error and cannot be used. Most of the time, schemas should be carefully managed so that each element and type is defined in exactly one schema document.

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.