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

Using Inline Schemas (XSD)

Beginning with Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office, support has been implemented to allow you to use inline XML schemas that conform to the XML Schemas (XSD) specification.

Inline schemas can be useful when it is inconvenient to physically separate the schema and the instance XML document. For example, if you generate an XSD schema from data retrieved from a database, it might be more convenient to put the schema and the data in the same file.

Note   Support for inline XDR schemas was previously implemented in MSXML 3.0 and 4.0. For more information, see Using Inline XDR Schemas.

In MSXML 5.0 and later, inline XSD schema support is enabled by default whenever you create a new DOM document or SAX stream. This support includes a compiling step for any inline schema contents, prior to subsequent parse/validate operations. This is done to ensure that the inline schema fragment is valid as an XML schema, before it is applied or used to validate the non-schema XML remainder of the DOM document or SAX stream.

The ability to control whether inline schemas are compiled and used to validate their host documents can be set in one of two ways, depending on whether you are working with the DOM or the SAX APIs:

If inline schema processing is turned off, inline schemas are treated no differently from any other XML document fragment, and any special meaning they have for validation is ignored.

Important   Because inline schema compilation can take place even when validation is turned off for the DOM or SAX instance, some parsing errors can occur if you compile inline schemas when you do not intend to validate the document. To avoid or resolve such errors, turn off inline schema support using the appropriate DOM or SAX mechanism, as mentioned above.

Inline schemas are referenced and handled in the same way as external schemas that are declared using either the schemaLocation attribute or the noNamespaceSchemaLocation attribute to specify a URI or path location to the external schema file.

Just like with external schemas, documents and document fragments validated using inline schemas must be identified by their namespace, which should match the targetNamespace attribute in the schema. For example, a schema with a target namespace of "http://example.com" is applied only to those fragments that also belong to the "http://example.com" namespace.

If a schema is used without targetNamespace, it is applied to the fragments, which belong to the default namespace. By design, inline schemas can never be applied to the root element.

In the following section, we will look at examples of how inline XSD schemas differ from external XSD schemas that reference an external location, such as another file or a schema cache.

Examples

This section provides the following examples of using inline schemas.