Microsoft XML 2.5 SDK


 

XML Schema Reference

[This is preliminary documentation and subject to change.]

Internet Explorer 5 includes support for XML Schema.

The W3C XML Activity Page states: "While XML 1.0 supplies a mechanism, the Document Type Definition (DTD) for declaring constraints on the use of markup, automated processing of XML documents requires more rigorous and comprehensive facilities in this area. Requirements are for constraints on how the component parts of an application fit together, the document structure, attributes, datatyping, and so on. The W3C XML Schema Working Group is addressing means for defining the structure, content and semantics of XML documents."

The XML Schema language is based on the XML-Data note submitted to the W3C. XML Schema as implemented in this release can be thought of as the subset of the XML-Data submission that corresponds to the feature set proposed for Document Content Description (DCD).

Microsoft is providing this release of XML Schema with data type support that might be useful for developers interested in building prototypes and gaining experience with schema and rich data types. Microsoft is actively involved in defining the emerging W3C XML schema standard and will track this effort. Developers should note that this version of XML Schema is subject to change.

Unlike the unique DTD syntax, XML Schema allows you to define the rules governing the relations between elements and attributes using a standard XML instance syntax, which can be parsed and managed using XML applications. XML Schema also adds support for namespaces, data types, and such useful features as range constraints.

The definitions in an XML schema are contained within the top-level Schema document element. The Schema document element definition must come from the namespace: xmlns="urn:schemas-microsoft-com:xml-data." The namespace declaration is an XML processing instruction (PI) as defined in the W3C XML Namespace Working Draft . It is convenient to make the Schema namespace the default namespace to avoid having to prefix all definitions within a schema. This documentation uses the convention that the schema namespace is the default namespace, and omits a prefix from all XML Schema element and attribute names.

The Schema document element in an XML Schema document should also contain namespace declarations for any other schemas, such as the namespace that defines the built-in data types for XML Schema.

<Schema name="myschema" xmlns="urn:schemas-microsoft-com:xml-data"
                        xmlns:dt="urn:schemas-microsoft-com:datatypes">
 <!-- ... -->
</Schema>

The Schema document element can contain any number of top-level declarations. The principal XML Schema elements include ElementType (which declares element types) and AttributeType (which declares attribute types). These elements must have an explicit name attribute that is unique within the schema. The element and attribute elements can appear within the ElementType element to constrain the content and attributes that can appear in elements of the named type. The ElementType attribute order and the group element allow you to further establish fine-grained definitions. The minOccurs and maxOccurs attributes allow you to define the number of occurrences of an element or group.

The content for an element of a given element type can be defined as one of four categories: empty (no content), text only, subelements only, or a mix of text and subelements. This choice is expressed in the ElementType attribute named content, which can take the values "empty," "textOnly," "eltOnly," and "mixed," respectively.

Element types and attribute types can constrain their values and contents to be instances of a particular data type, referenced from the datatype element namespace. To use the datatype namespace in a schema, it must be declared within the Schema element. The dt:type attribute can then be used to reference data types; in the Internet Explorer 5 implementation, element and attribute types can take "rich" data types. For a complete description of data types, see XML Data Types Reference.

Finally, note that in XML, schema files are optional and are not required. Some XML applications do not require validation and do not specify a schema file. For a detailed description and examples of these elements, see the reference topic for each XML Schema element.

XML Schema Elements

The following table describes the XML Schema elements.

attribute Refers to a declared attribute type that can appear within the scope of the named ElementType element.
AttributeType Defines an attribute type for use within the Schema element.
datatype Specifies the data type for the ElementType or AttributeType element.
description Provides documentation about an ElementType or AttributeType element.
element Refers to a declared element type that can appear within the scope of the named ElementType element.
ElementType Defines an element type for use within the Schema element.
group Organizes content into a group to specify a sequence.
Schema Identifies the start of a schema definition.

XML Data Types Support

Support for data types is integrated into this release. For more information, see XML Data Types Reference.

See Also

XML Schema Developer's Guide

XML DOM Reference