![]() |
Considering schemas | Table of contents | Indexes | Derivation, tolerance and validity | ![]() |
|||
| equivalence_class parameter_entity schema ![]() type | XML Schema types and equivalence classes |
| reconstructing DTD best practice |
Thompson, Henry S. ![]() |
| Henry S. Thompson |
Edinburgh ![]() HCRC Language Technology Group ![]() Scotland ![]() | HCRC Language Technology Group,
Division of Informatics,
University of Edinburgh,
2 Buccleuch Place Edinburgh EH8 9LW Scotland email: ht@cogsci.ed.ac.uk |
| Biography |
| Abstract |
Introduction |
Document structure definition in XML Schema |
<xs:complexType name="meeting"> <xs:all> <xs:element ref="venue"/> <xs:element ref="organiser"/> <xs:element ref="participants"/> </xs:all> <xs:attribute name="when" type="xs:date" use="required"/> </xs:complexType> |
| Note: |
| An element declaration associates a tag with a type definition, thereby requiring elements in instances with that tag to conform to the definition, for example: |
<xs:element name="appointment" type="meeting"/> |
| Taken together the above pair of definition and declaration is similar in effect to the following SGML declarations: |
<!ELEMENT appointment (venue & organiser & participants)> <!ATTLIST meeting when CDATA #REQUIRED> |
Structuring the type space: type definition derivation in XML Schema |
<!ENTITY % cellhalign "align (left|center|right|justify|char) #IMPLIED char %Character; #IMPLIED charoff %Length; #IMPLIED" > |
| This defines the cellhalign parameter entity with text for three attribute declarations. Virtually all the table-related element types then use this parameter entity, for example: |
<!ATTLIST thead %attrs; %cellhalign; %cellvalign; > |
<xs:complexType name="tabular" content="empty"> <xs:attribute name="align" type="halignPos"/> <xs:attribute name="char" type="Character"/> . . . </xs:complexType> |
| Then all the relevant elements would have type definitions derived from this one, for example: |
<xs:complexType name="tableBlock" content="elementOnly" base="tabular" derivedBy="extension"> <xs:element ref="tr" minOccurs="1" maxOccurs="unbounded"/> </xs:complexType> <xs:element name="thead" type="tableBlock"/> <xs:element name="tbody" type="tableBlock"/> <xs:element name="tfoot" type="tableBlock"/> |
Type definition derivation details: extension |
| Consider the following two type definitions: |
<xs:complexType name='name'> <xs:element name='title' minOccurs='0'/> <xs:element name='forename' minOccurs='0' maxOccurs='unbounded'/> <xs:element name='surname'/> </xs:complexType> <xs:complexType name='fullName' base='name' derivedBy='extension'> <xs:element name='suffix' minOccurs='0'/> </xs:complexType> |
| Now consider members of the two types defined above: |
<...> <foreName>George</foreName> <foreName>W</foreName> <surname>Bush</surname> </...> <...> <foreName>Albert</foreName> <surname>Gore</surname> <suffix>Jr.</suffix> </...> |
| The second, a member of the derived type, contains as a prefix a member of the base type. |
Type definition derivation details: restriction |
| A different important relationship holds between the members of a type defined by restriction.: every member of a type defined by restriction is necessarily also a member of its base. |
| Simple types may also be defined by restricting other simple type definitions, for instance be reducing the membership of an enumerated type or narrowing a value range. |
| Consider the following three type definitions, a simplified version of definitions from the schema for schemas: |
<xs:complexType name="group"> <xs:element ref="particle" minOccurs="0" maxOccurs="unbounded"/> <xs:attribute name="name" use="optional" type="xs:NCName"/> <xs:attribute name="ref" use="optional" type="xs:QName"/> </xs:complexType> <xs:complexType name="topLevelGroup" base="group" derivedBy="restriction"> <xs:element ref="particle" minOccurs="1" maxOccurs="unbounded"/> <xs:attribute name="name" use="required" type="xs:NCName"/> <xs:attribute name="ref" use="prohibited" type="xs:QName"/> </xs:complexType> <xs:complexType name="refToGroup" base="group" derivedBy="restriction"> <xs:element ref="particle" minOccurs="0" maxOccurs="0"/> <xs:attribute name="name" use="prohibited" type="xs:NCName"/> <xs:attribute name="ref" use="required" type="xs:QName"/> </xs:complexType> |
| The first definition defines a group as having optional name and ref attributes and any number of <particle> as content. The second restricts this for use at the top level, to define a group, in which case the name and at least one <particle> are required, while the ref is prohibited. For use within content models, the third restricts in the other direction, requiring a ref (to a top-level defined group, by name and namespace), and forbidding either name or content. It should be clear that any member of either of the two derived types is a member of the more general base. |
Element equivalence classes |
| The mechanism of type definition derivation described above allows XML Schema authors to reconstruct usages of parameter entities which reflect commonality of structure: |
<!ENTITY % local.list.class ""> <!ENTITY % list.class "ulist|olist|slist|glist %local.list.class;"> . . . <!ELEMENT div1 (head, (. . .|%list.class;|. . .)*, div2*)> |
| References to %list.class; appear elsewhere in other content models in the DTD as well, and no member of the class appears anywhere _else_ on its own. XML Schema provides for reflecting this kind of element commonality using the notion of (asymmetric) equivalence class: any top-level element declaration can nominate another top-level declaration as one it is equivalent to. The set of all declarations which identify (perhaps via several steps) another declaration as their equivalence class (using the equivClass attribute) form itsequivalence class . Whereever it appears in content models, isntances may contain not only it, but also any member of its equivalence class. One possible XML Schema reconstruction of the above example would look like this: |
<xs:element name="div1"> <xs:complexType> <xs:element ref="head"/> <xs:choice minOccurs="0" maxOccurs="unbounded"> . . . <xs:element ref="list"/> . . . </xs:choice> <xs:element ref="div2" minOccurs="0" maxOccurs="unbounded"/> </xs:complexType> </xs:element> <xs:element name="list" abstract="true" type="listType"/> <xs:element name="slist" equivClass="list" type="simpleListType"/> <xs:element name="flaggedList" abstract="true" equivClass="list"/> <xs:element name="ulist" equivClass="flaggedList" type="bulletedListType"/> <xs:element name="olist" equivClass="flaggedList" type="enumeratedListType"/> <xs:element name="glist" equivClass="list" type="glossaryListType"/> |
| Via one or two steps, all four of glist , olist , slist and ulist are declared as part of list 's equivalence class, so all of them may occur within <div1> in the indicated place. list itself and flaggedList are declared as abstract , meaning they can't themselves actually appear in documents -- they are included in the schema simply to provide a potentially useful layer of structuring. |
| Two further aspects of this design disserve mention. No special provision for subsequent extension of the membership of the classes involved is required (this is what the local.list.class entity is for in the original DTD). Another XML Schema document which includes one with the above definitions by reference (by one of several mechanisms provided for modular and/or multi-namespace schema specification, see ) can add its own elements to one or the other class simply by referring to them via the equivClass attribute in its own declarations. Also, in order to enforce a degree of coherency, XML Schema does require that the type definition of elements declared as equivalent to others must be derived from its type definition. In the above example, this means that, for instance, enumeratedListType would have to be derived from listType (the type definition of flaggedList , by default). |
Conclusion |
| The above examples have introduced two distinct but related mechanisms which the XML Schema language provides for reconstructing some common uses of parameter entities in structured DTD design. By bringing these constructs inside the language, rather than relegating them to the status of conventions for the use of text substitution, XML Schema has endorsed and facilitated an approach to structured document type definition of recognised power and generality. |
| Bibliography |
|
|
|
|
![]() |
Considering schemas | Table of contents | Indexes | Derivation, tolerance and validity | ![]() | |||