STEP 3: Datatypes

$Id: step3e.html 1.4 2000/02/29 12:02:26 murata Exp $

text by MURATA Makoto

html by NAMBA Ryosuke


STEP 3 introduces datatypes.

1. Datatypes of XML Schema Part 2

XML Schema Part 2 introduces many built-in datatypes. They are designed so that other specifications can utilize them. RELAX borrows all these built-in datatypes.

Some of the built-in datatypes of XML Schema Part 2 are borrowed from XML DTD and the others are newly introduced. Those borrowed from XML DTD are shown as below:

Next, built-in datatypes newly introduced by XML Schema Part 2 are shown below:

In XML Schema Part 2, when users reference to these built-in datatypes, users can further specify constraints such as value ranges. The same thing applies to RELAX. However, unlike XML Schema Part 2, RELAX does not allow users to define their own datatypes.

2. Datatypes unique to RELAX

Datatypes unique to RELAX are none and emptyString.

2.1 none

none is an empty datatype. No character strings belong to this datatype. RELAX uses none so as to prohibit attributes. In the following example, the class attribute is prohibited. The motiviation for none will become clear in STEP 8.

<tag name="p">
  <attribute name="class" type="none"/>
</tag>

2.2 emptyString

emptyString is a datatype that allows the empty string only. This datatype is compatible with EMPTY of DTD.

<elementRule pred="em" type="emptyString"/>

This elementRule allows the following two elements only. Whitespace characters may not occur between <em> and </em>.

<em/>
<em></em>

3. Additional constraints

Like XML Schema Part 2, RELAX allows users to specify additional constraints on datatypes. For example, users can specify integer and further specify a constraint "18 thru 65". The syntax for such additional constraints is the same as in XML Schema Part 2.

3.1 elementRule

To impose constraints on a datatype specified by elementRule, attach child elements to the elementRule.

In the following example, the hedge model for the element type age is a reference to integer. minInclusive and maxInclusive represent constraints on minimum and maximum values, respectively. Thus, permissible contents of age elements are character strings representing integers from 18 to 65.

<elementRule pred="age" type="integer">
  <minInclusive value="18"/>
  <maxInclusive value="65"/>
</elementRule>

A age element can contain string "20" as its content.

<age>20</age>

But string "11" is not allowed.

<age>11</age>

3.2 attribute

To impose constraints on a datatype specified by attribute, attach child elements to attribute.

In the following example, the sex attribute of employee is constrained to be either man or woman. Here, enumeration is a constarint which specifies a permissible value.

<tag name="employee">
  <attribute name="sex" type="NMTOKEN">
    <enumeration value="man"/>
    <enumeration value="woman"/>
  </attribute>
</tag>

The sex attribute can have the string "man".

<employee sex="man"/>

But it cannot contain the string "foo".

<employee sex="foo"/>

4. Summary

STEP 3 provides more than enough features to play with. Enjoy and RELAX!


mura034@attglobal.net

Valid HTML 4.0!