Including other models

Within DTDs, parameter entities are often used to reference external document model components. For example, a commonly used table model, such as the CALS or HTML model, is often referenced from numerous document models that need to include tables. While general entities (see Chapter 4) can be used in all XML documents, and therefore in XML Schema documents, it is not necessary to rely upon this feature. The XML Schema standard has its own capabilities for sharing models.

Schema-switching

As already described, it is possible to let the XML processor do all of the work of including other models, using namespaces and the Any element (or the AnyAttribute element) to identify the namespace of the other model, and the valid locations where elements (or attributes) from this model may be used. However, when namespaces are not being used, it becomes necessary to copy one model's definitions into another model.

Including another schema

The Include element references a schema file, using a URL reference in the SchemaLocation attribute, the contents of which are to be included in the main file:

<include schemaLocation="tables.xsd" />

This element must occur before any element, attribute or complex definition. The schema to be included must also have the same target namespace (or the same absence of a target namespace). Consequently, this mechanism cannot be used to share model fragments among numerous models, when the models concerned target different namespaces.

Although the file to be included must be a complete schema document in its own right, capable of being used in isolation, typically it will only be used by reference from other schema documents, and never directly from an XML instance document. A schema-sensitive processor is expected to be able to call in the document whenever it is referenced by another schema document, and treat its contents as if they had existed in the primary file. The effect should be the same as using the XIn clude standard (see Chapter 12) to embed the contents of the root element, before attempting to interpret the model, but with the additional refinement of ensuring that the schema content model remains valid.

Importing definitions

A schema author can reference definitions in other schemas, and has the choice of whether to use original element and attribute names, or to override them. This approach depends upon the author of the other schema document creating named data types (introduced below), rather than simply creating element and attribute definitions (and importing is discussed in more detail in the next chapter).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.105