Unlike a Document Type Definition (DTD), XML Schema allows you to specify a data type for an element or attribute. Data types indicate the format of the data, provide for validation of the type by the XML parser, and enable processing specific to the data type in the XML Document Object Model (DOM).
Data type support includes primitive data types common to programming languages as well as the special attribute types included in the XML Language Specification (for example, ID, IDREF, and NMTOKEN). A complete list of the data types can be found in the XML Data Types Reference.
To use the data type support included with Internet Explorer 5, your XML Schema must include the datatypes namespace. The top-level <Schema> element declaration would look like this:
<Schema name="myschema" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <!-- ... --> </Schema>
Within the <Schema > element, data types can be specified on an <ElementType> or <AttributeType> basis using one of two forms:
Both forms are demonstrated below shown in a
<ElementType name="pages" dt:type="int"/>
<ElementType name="pages"> <datatype dt:type= "int"/> </ElementType>
Note that although XML Schema support in Internet Explorer 5 allows data types to be specified within attributes, only the following data types are supported within attributes by the parser and DOM: string, id, idref, idrefs, nmtoken, nmtokens, entity, entities, enumeration, and notation.
In the following schema, the shipTo attribute has a data type of "idref."
<AttributeType name="shipTo" dt:type="idref"/> <attribute type="shipTo"/>
An attribute whose data type is "idref" holds an identifying value in the document instance, a value that does not appear on any other idref attribute in the document.
Two other related data types are "id" and "idrefs." An attribute of type "id" acts as a reference to the element with the matching id value. The data type "idrefs" is similar to "id," but it holds a list of ids, separated by spaces. For example,
<PurchaseOrder items="Item-1 Item-2">
In Internet Explorer 5.01, elements support the id attribute data type. You can declare it on an element node through schema just as you would declare it on an attribute node. The two ways of doing this are with the dt:type attribute on the <ElementType> element, or with the <datatype> element within an <ElementType>.
Below, with the dt:type attribute on the <ElementType> element:
<ElementType name="Element1" dt:type="id"/>
or with the <datatype> element within an <ElementType > element:
<ElementType name="Element2"> <datatype dt:type="id"> </ElementType>
Using other attribute data types on elements is not currently supported; however, their use does not cause a validation error to occur.
In Internet Explorer 5.01, you can use simple data types (for example, int, boolean, float, and so on) when you declare an attribute. Use either the dt:type attribute on the <AttributeType > element, or a <datatype> element within an <AttributeType> element.
Below, the dt:type attribute on the <AttributeType> element:
<AttributeType name="att1" dt:type="int"/> <ElementType name="Element1"> <attribute type="att1"/> </ElementType>
or with a <datatype> element within an <AttributeType> element:
<AttributeType name ="y"/> <datatype dt:type="int"/> </AttributeType> <ElementType name="x"> <attribute type="y"/> <ElementType>