$Id: step5e.html 1.4 2000/02/29 12:03:19 murata Exp $
Large modules are hard to maintain. STEP 5 introduces a mechanism for dividing a module into several pieces, which can be maintained easier.
Suppose that we rewrite a DTD containing 200 element types in
RELAX. This size is a fairly large, but is not uncommon. For each
element type, RELAX needs an elementRule and a
tag. If each elementRule and
tag requires three lines, the total is 1200 lines. If we
write extensive documentation, the total may become 3000 lines or even
more. This size is too large to put in a single file.
Even DTD provides external parameter entities so as to divide large DTDs into modules and maintain each module independently. RELAX strongly requires some mechanism for dividing large modules.
include elementIn RELAX, a module can reference to another module by the
include element. The include element is
replaced with the content of the referenced module.
We shall examine an example of include. First, a
module to be included is as below:
<module
moduleVersion="1.2"
relaxCoreVersion="1.0"
targetNamespace=""
xmlns="http://www.xml.gr.jp/2000/relaxCore">
<interface/>
<elementRule pred="bar" type="emptyString"/>
<tag name="bar"/>
</module>
This module contains an elementRule and
tag for the element type bar. The
interface element is empty. Suppose that this module is
stored in bar.rlx.
Next, a module which references to and includes this module is as below:
<module
moduleVersion="1.2"
relaxCoreVersion="1.0"
targetNamespace=""
xmlns="http://www.xml.gr.jp/2000/relaxCore">
<interface>
<export labels="foo"/>
</interface>
<elementRule pred="foo">
<ref label="bar"/>
</elementRule>
<tag name="foo"/>
<include moduleLocation="bar.rlx" />
</module>
This module contains an elementRule and
tag for the element type foo. The include
at the end of this this module references to bar.rlx
via the moduleLocation attribute.
The include element is replaced by the body of the
referenced module, which the content of the module
element except the interface element. In this example,
replacement is done as below:
<module
moduleVersion="1.2"
relaxCoreVersion="1.0"
targetNamespace=""
xmlns="http://www.xml.gr.jp/2000/relaxCore">
<interface>
<export labels="foo"/>
</interface>
<elementRule pred="foo">
<ref label="bar"/>
</elementRule>
<tag name="foo"/>
<elementRule pred="bar" type="emptyString"/>
<tag name="bar"/>
</module>
interface elementsIn the above example, the interface element of the
referenced module is empty. Suppose that an export
element is supplied in the interface element.
<module
moduleVersion="1.2"
relaxCoreVersion="1.0"
targetNamespace=""
xmlns="http://www.xml.gr.jp/2000/relaxCore">
<interface>
<export labels="bar"/>
</interface>
<elementRule pred="bar" type="emptyString"/>
<tag name="bar"/>
</module>
In this case, the children of the interface element in
the referenced module are attached to the interface
element in the referencing module. In this example, the result of
replacement is as below:
<module
moduleVersion="1.2"
relaxCoreVersion="1.0"
targetNamespace=""
xmlns="http://www.xml.gr.jp/2000/relaxCore">
<interface>
<export labels="foo"/>
<export labels="bar"/>
</interface>
<elementRule pred="foo">
<ref label="bar"/>
</elementRule>
<tag name="foo"/>
<elementRule pred="bar" type="emptyString"/>
<tag name="bar"/>
</module>
STEP 5 makes it easy to maintain large modules. Enjoy and RELAX!