Representing the XDR Schema as a DTD

MSXML 5.0 SDK

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

Representing the XDR Schema as a DTD

The following is an example of representing the XML-Data Reduced (XDR) schema with a document type definition (DTD). However, the representation is not exact.

  • Schemas and DTDs use different content models. When the model is defined as open, the element can include ElementType elements, AttributeType elements, and mixed content not specified in the content model. When the model is defined as closed, the element cannot include elements or mixed content not specified in the content model. The DTD uses a closed content model; schemas use an open content model.
  • Possible data types for elements and attributes are different. In the following code sample, the data types parameter, entity, lists the data types for both the attributes and elements of the dt:type attribute for the datatype element. In MSXML 2.0 and later, support for these data types is limited. The attributes only support the first 10 types (which map to DTD attribute types) and elements only support from "string" through "uuid"; therefore an element cannot behave like an id or idref.
  • Placement of xmlns namespace declarations cannot be modeled very well using a DTD. In a real schema, the xmlns:dt attributes can go anywhere. Any other xmlns declaration can also appear because schemas follow an open content model. This way you can add extended information in your schemas for your own use.
  • The maxOccurs attribute can only have the values "1" or "*" and this cannot be modeled using a DTD enumeration because "*" is not a valid name token.
  • ElementType and AttributeType elements can only have one datatype child element. DTDs cannot model this sort of ordinality, particularly when other child elements are allowed.
<!--
  The possible element datatypes according to
    http://msdn.microsoft.com/xml/schema/reference/datatypes.asp
-->
<!ENTITY % datatypes "(entity | entities | enumeration | id | idref | idrefs
| nmtoken | nmtokens | notation | string | bin.base64 | bin.hex | boolean |
char | date | dateTime | dateTime.tz | fixed.14.4 | float | int | number |
time | time.tz | i1 | i2 | i4 | r4 | r8 | ui1 | ui2 | ui4 | uri |
uuid)" >
<!--  *** datatype **** -->
<!ELEMENT datatype  (description)*>
<!ATTLIST datatype
    dt:type %datatypes;  #IMPLIED
    xmlns:dt CDATA #FIXED "urn:schemas-microsoft-com:datatypes"
>
<!--  ***** description  ***** -->
<!ELEMENT description (#PCDATA) >
<!-- ****  element  ***** -->
<!-- additional constraint on maxOccurs is that it must be 1 or "*" -->
<!ELEMENT element  (description)* >
<!ATTLIST element
   type IDREF        #REQUIRED
   minOccurs  CDATA  #IMPLIED
   maxOccurs  CDATA  #IMPLIED
>
<!-- ****  attribute   ***** -->
<!ELEMENT attribute  (description)* >
<!ATTLIST attribute
   type       IDREF    #REQUIRED
   default    CDATA        #IMPLIED
   required   (yes | no)   "no"
>
<!-- ****  AttributeType   ***** -->
<!ELEMENT AttributeType (datatype | description)* >
<!ATTLIST AttributeType
   name         ID              #REQUIRED
   default      CDATA           #IMPLIED
   dt:type      %datatypes;     #IMPLIED
   dt:values    CDATA           #IMPLIED
   required     (yes | no)      #IMPLIED
   xmlns:dt CDATA #FIXED "urn:schemas-microsoft-com:datatypes"
>
<!-- ****  ElementType   ***** -->
<!ELEMENT ElementType (datatype | description | AttributeType | attribute | element | group)* >
<!ATTLIST ElementType
   name  ID                       #REQUIRED
   model (open | closed)          #IMPLIED
   content (empty | textOnly | eltOnly | mixed) #IMPLIED
   order   (one | seq | many)     #IMPLIED
   dt:type %datatypes;            #IMPLIED
   dt:values  CDATA               #IMPLIED
   required  (yes | no)           #IMPLIED
   xmlns:dt CDATA #FIXED "urn:schemas-microsoft-com:datatypes"
>
<!-- ****  group   ***** -->
<!ELEMENT group  (group | element | description)*>
<!ATTLIST group
   minOccurs   CDATA              #IMPLIED
   maxOccurs   CDATA              #IMPLIED
   order      (one | seq | many)  #IMPLIED
>
<!-- ****  Schema   ***** -->
<!ELEMENT Schema  (AttributeType | ElementType | description )* >
<!ATTLIST Schema
   name  CDATA #IMPLIED
   xmlns:dt CDATA #FIXED "urn:schemas-microsoft-com:datatypes"
>