ENGLISHJAPANESE
<< HOW TO RELAX/Part 1: RELAX Core/STEP 9: Hedge content model element >>

STEP 9: Hedge content model element


RELAX allows element elements as permissible hedge models. They are mere syntax sugar, and are expanded as ref, elementRule, and tag elements. In this section, we show motivation behind element elements and then present the mechanism.

Simulating programming languages and database languages

RELAX is an extension of DTDs, and is based on a grammatical data model. This model is very different from data models of programming languages and database systems. On the other hand, RELAX should be able to mimic declarations in programming languages and schemata in database languages.
In programming languages, we declare variables and attach datatypes to them. In the next example, variables x and y are declared and a datatype int is attached to them.

public class Point {
    int x;
    int y;
}

When a variable x is declared in another class, it may have a different type. In the next example, a datatype float is attached to x of the class Foo.

public class Foo {
    float x;
}

The element element

The element element is an element hedge model that specifies both a variable name and type name. An element element always has the name attribute and type attribute. Furthermore, it may have the occurs attribute.

<element name="tag-name" type="datatype-name"/>

<element name="tag-name" type="datatype-name" occurs="*"/>

Use of element elements allows tag and elementRule elements such as below:

<tag name="Point"/>

<elementRule role="Point">
  <sequence>
    <element name="x" type="integer"/>
    <element name="y" type="integer"/>
  </sequence>
</elementRule>

A Point such that x=100 and y=200 can be represented by an XML document as below:

<Point>
  <x>100</x>
  <y>200</y>
</Point>

Expansion to ref, elementRule, and tag elements

The element element is merely syntax sugar. Each element element in a hedge model is replaced by a ref element, while an elementRule element and tag element are generated.
The elementRule in the previous subsection is duplicated below. Two element elements in this example have the type attribute. Let us consider how these element elements are expanded.

<elementRule label="Point">
  <sequence>
    <element name="x" type="integer"/>
    <element name="y" type="integer"/>
  </sequence>
</elementRule>

Each of the element elements is replaced by a ref element. Furthermore, an elementRule element and tag element are generated for each element element. As a hedge model, each elementRule has a reference to the datatype specified by the type attribute of the original element element.

<elementRule label="Point">
  <sequence>
    <ref label="Point$1"/>
    <ref label="Point$2"/>
  </sequence>
</elementRule>

<elementRule role="Point$1" label="Point$1" type="integer"/>
<tag role="Point$1" name="x"/>

<elementRule role="Point$2" label="Point$2" type="integer"/>
<tag role="Point$2" name="y"/>

When an element element has the occurs attribute, it is copied to the generated ref element. For example, suppose that the elements in the first elementRule specifies occurs="?" (see below).

<elementRule label="Point">
  <sequence>
    <element name="x" type="integer" occurs="?"/>
    <element name="y" type="integer" occurs="?"/>
  </sequence>
</elementRule>

The result of expansion is as below:

<elementRule label="Point">
  <sequence>
    <ref label="Point$1" occurs="?"/>
    <ref label="Point$2" occurs="?"/>
  </sequence>
</elementRule>

<elementRule role="Point$1" label="Point$1" type="integer"/>
<tag role="Point$1" name="x"/>

<elementRule role="Point$2" label="Point$2" type="integer"/>
<tag role="Point$2" name="y"/>

Expansion procedure

In this section, we summarize expansion of element elements.

Generating ref elements

A ref element is generated. As the value of its label attribute, we generate a label that does not conflict with any other label. If the element has the occurs attribute, it is copied to the generated ref element.

Generating elementRule elements

An elementRule element is generated. As the value of its role attribute, we generate a role that does not conflict with any other role. The value of the label attribute is the label generated together with the ref element. As the hedge model of this elementRule, the type attribute of the element element is copied.

Generating tag elements

A tag element is generated. Its role attribute specifies the role automatically generated together with the elementRule. The name attribute of the generated tag specifies the value of the name attribute of the original element element.

Summary

For users of programming languages and database languages, description by element elements probably look very natural and easy to understand. Enjoy and RELAX!

<< HOW TO RELAX/Part 1: RELAX Core/STEP 9: Hedge content model element >>