Specifying Elements

<<< For every element in EWEML, we'll need to specify:

  1. An element rule, which tells what sub-elements it has (if any).
  2. The name of the tag that follows that rule.

Here is how to define the <report> element.

<elementRule role="report">
        <ref label="datestamp"/>
        <ref label="station"/>
        <ref label="temperature"/>
        <ref label="wind"/>

<tag name="report"/>

Since the <elementRule> consists of several elements, they are given in <sequence> as references (<ref>) to the definitions which are to follow.

The <datestamp> element is a simple one; it has no attributes and can't have any other elements inside it. However, the information between the beginning and ending tags must be in a specific format; that of a date. In RELAX we say:

   <elementRule role="datestamp" type="date"/>
   <tag name="datestamp/>

The next element in our weather report is the <station> information, shown below.

     <station fullname="San Jose" abbrev="KSJC">

This has sub-elements, but it also has attributes. Here's the specification:

    <elementRule role="station">
            <ref label="latitude"/>
            <ref label="longitude"/>

    <tag name="station">
        <attribute name="fullname" type="string" required="true"/>
        <attribute name="abbrev" type="string" required="true"/>

    <elementRule role="latitude" type="decimal"/>
    <tag name="latitude"/>

    <elementRule role="longitude" type="decimal"/>
    <tag name="longitude"/>

Again, this is fairly easy to read. The <station> element is made up of the <latitude> and <longitude> elements, which must contain decimal numbers between their beginning and ending tags. The RELAX <tag> element describes the tag's required fullname and abbrev attributes, both of which are strings.

The only difference so far between this and a DTD is that we can specify what kind of content an element must have (date, string, decimal, etc.) Let's use the power of RELAX to be much more specific on what content elements and attributes may have. >>>

  1. Validating XML with RELAX
  2. Validity and the DTD
  3. Validity and RELAX
  4. Specifying Elements
  5. Making Validation More Specific
  6. Further Specifications
  7. Enumerations
  8. The Big Picture
  9. Summary