ENGLISH | JAPANESE |
<< | HOW TO RELAX/Part 1: RELAX Core/STEP 9: Hedge content model element | >> |
element
element
ref, elementRule
, and
tag
elements
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.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; } |
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> |
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.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 element
s 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"/> |
element
elements.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.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.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.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 | >> |