ENGLISHJAPANESE
<< HOW TO RELAX/Part 1: RELAX Core/STEP 3: Datatypes >>

STEP 3: Datatypes


$Id: step3.sdoc 1.10 2000/08/26 03:14:38 murata Exp $
STEP 3 introduces datatypes.

Datatypes of XML Schema Part 2

XML Schema Part 2introduces 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; 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.

Datatypes unique to RELAX

Datatypes unique to RELAX are none and emptyString.

none

noneis 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.

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

Thus, the following start tag is not permitted.

  <p class="foo">

emptyString

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

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

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

<em/>

<em></em>

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.

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 role="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>

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 constraint 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"/>

Summary

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

<< HOW TO RELAX/Part 1: RELAX Core/STEP 3: Datatypes >>