CIS97 YT > Midterm Project 1 > Relax NG Projects > World Factbook Grammar

Relax NG Projects
World Factbook

Project Index | Documentation | Relax NG | Sample XML File

<!-- =========================================== -->
<!-- CIS97YT Midterm 1                           -->
<!-- File: chang_k_midterm1.rng                  -->
<!-- Subject: Creating and Using an RNG File     -->
<!-- Written by: Ko Chang                        --> 
<!-- Date: 05/29/2002                            -->
<!-- =========================================== -->


<grammar xmlns="http://relaxng.org/ns/structure/1.0"
    datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

<start>

<element name="world-factbook">  
  <element name="country-list">
    <oneOrMore>
      <element name="country">
        <element name="name">
          <text/>
        </element>
        <ref name="Profile"/>
      </element>  <!-- end country element -->
    </oneOrMore>
  </element>      <!-- end country-list element -->
</element>        <!-- end world-factbook element -->

</start>


<!-- define Profile reference -->
<define name="Profile">
  <element name="profile">
    <ref name="Introduction"/>
    <ref name="Geography"/>
    <ref name="People"/>
    <ref name="Government"/>
    <ref name="Economy"/>
    <attribute name="name"/>
    <attribute name="code">
      <data type="ID"/>
    </attribute>
  </element>      <!-- end of profile element -->
</define>         
<!-- end of Profile reference -->

<!--define Introduction reference -->
<define name="Introduction">
  <element name="introduction">
    <element name="background">
      <interleave>
        <text/>
        <zeroOrMore>
          <ref name="Inline"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="Paragraph"/>
        </zeroOrMore>
      </interleave>
    </element>
  </element>      <!-- end of introduction element -->
</define>         
<!-- end of Introduction reference -->

<!-- define Geography reference -->
<define name="Geography">
  <element name="geography">
    <element name="location">
      <text/>
    </element>

    <interleave>
      <element name="coordinates">
        <empty/>
        <attribute name="latitude">
          <data type="string">
            <param name="pattern">([1-9]|[12]\d|3[0-5])?\d \d{2} [NS]</param>
          </data>
        </attribute>
        <attribute name="longitude">
          <data type="string">
            <param name="pattern">([1-9]|[12]\d|3[0-5])?\d \d{2} [EW]</param>
          </data>
        </attribute>
      </element>      <!-- end of coordinates element -->

      <element name="area">
        <element name="total">          
          <ref name="Area"/>
        </element>
        <element name="land">       
          <ref name="Area"/>
        </element>
        <element name="water">          
          <ref name="Area"/>
        </element>
      </element>      <!-- end of area element -->

      <element name="climate">
        <interleave>
          <text/>
          <zeroOrMore>
            <ref name="Inline"/>
          </zeroOrMore>
        </interleave>
      </element>      <!-- end of climate element -->

      <optional>
        <element name="note">
          <interleave>
            <text/>
            <zeroOrMore>
              <ref name="Inline"/>
            </zeroOrMore>
            <zeroOrMore>
              <ref name="Paragraph"/>
            </zeroOrMore>
          </interleave>
        </element>
      </optional>     <!-- end of note element -->
    </interleave>
  </element>      <!-- end of geography element -->
</define>
<!-- end of Geography reference -->

<!-- define People reference -->
<define name="People">
  <element name="people">
    <element name="population">
      <data type="string">
        <param name="pattern">\d{1,3}(,\d{3})*</param>
      </data> 
    </element>        <!-- end of population element -->

    <element name="age-structure">
      <element name="y0-14">
        <ref name="Age"/>
      </element>
      <element name="y15-64">
        <ref name="Age"/>
      </element>
      <element name="y65plus">
        <ref name="Age"/>
      </element>
    </element>        <!-- end of age-structure element -->

    <element name="sex-ratio">
      <attribute name="total">
        <data type="decimal">
        <param name="minExclusive">0</param>
        </data>
      </attribute>
      <attribute name="stat">
        <value type="string">male(s)/female</value>
      </attribute>
    </element>        <!-- end of sex-ratio element -->
    
    <element name="nationality">
      <text/>
    </element>        <!-- end of nationality element -->

    <element name="ethnic">     
      <text/>
      <zeroOrMore>
        <ref name="List"/>
      </zeroOrMore>
    </element>        <!-- end of ethnic element -->

    <element name="religions">
      <text/>
      <zeroOrMore>
        <ref name="List"/>
      </zeroOrMore>
    </element>        <!-- end of religions element -->

    <element name="language">
      <text/>
      <zeroOrMore>
        <ref name="List"/>
      </zeroOrMore>
    </element>        <!-- end of language element -->

  </element>      <!-- end of people element -->
</define>
<!-- end of People reference -->

<!-- define Government reference -->
<define name="Government">
  <element name="government">
    <element name="name">
      <element name="conventional-long">
        <text/>
      </element>
      <element name="conventional-short">
        <text/>
      </element>
    </element>        <!-- end of name element -->

    <element name="type">
      <text/>
    </element>        <!-- end of type elelment -->

    <element name="capital">
      <text/>
    </element>        <!-- end of capital elelment -->
    
    <element name="independence">
      <element name="date">
        <optional>
          <element name="month"><text/></element>
        </optional>
        <optional>
          <element name="day"><text/></element>
        </optional>
        <element name="year"><text/></element>
      </element>
    </element>        <!-- end of independence element -->

    <element name="suffrage">
       <text/>
    </element>
  </element>      <!-- end of government element -->
</define>
<!-- end of Government reference -->

<!-- define Economy reference -->
<define name="Economy">
  <element name="economy">
    <element name="overview">
    <interleave>
        <text/>
        <zeroOrMore>
          <ref name="Inline"/>
        </zeroOrMore>
        <zeroOrMore>
          <ref name="Paragraph"/>
        </zeroOrMore>
    </interleave>
    </element>        <!-- end of overview element -->

    <interleave>
    <element name="gdp">
        <empty/>
        <ref name="Amount"/> 
    </element>    <!-- end of gdp element -->

    <element name="labor-force">
        <data type="string">
          <param name="pattern">\d{1,3}(,\d{3})*(\.\d{1,2})?( [bm]illion)?</param>
        </data>
    </element>    <!-- end of labor-force element -->

    <element name="export">
        <empty/>
        <ref name="Amount"/>      
    </element>        <!-- end of export element -->

    <element name="import">
        <empty/>
        <ref name="Amount"/>
    </element>        <!-- end of import element -->

    <element name="currency">
        <text/>
    </element>    <!-- end of currency element -->

    <element name="exchange-rate">
        <data type="decimal">
            <param name="minExclusive">0</param>
        </data>     
        <attribute name="base">       
          <value type="string">per US dollar</value> 
        </attribute>
    </element>    <!-- end of exchange-rate element -->
    </interleave>
  </element>      <!-- end of economy element -->
</define>
<!-- end of Economy reference -->

<!-- define Area reference -->
<define name="Area">  
    <data type="string">
      <param name="pattern">\d{1,3}(,\d{3})* sq (km|mile)</param>
    </data>  
</define>
<!-- end of define Area reference -->

<!-- define Age reference -->
<define name="Age">  
    <data type="decimal">
      <param name="minExclusive">0</param>
      <param name="maxExclusive">100</param>
    </data>  
    <attribute name="units">
      <value type="string">%</value>
    </attribute>
</define>
<!-- end of define Age reference -->

<!-- define Amount reference -->
<define name="Amount">
  <attribute name="amount">
    <data type="string">
       <param name="pattern">$\d+(\.\d{1,2})?</param>       
    </data>
  </attribute>
  <attribute name="units">
    <choice>
      <value type="string">million</value>
      <value type="string">billion</value>
    </choice>
  </attribute>
</define>
<!-- end of Amount reference -->
    
<!-- define Subset reference -->
<define name="Subset">
  <interleave>
      <text/>
      <zeroOrMore>
        <ref name="Inline"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="Paragraph"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="List"/>
      </zeroOrMore>
  </interleave>
</define>
<!-- end of Subset reference -->

<!-- define Inline reference 
     choice of either em element or strong element for Inline element
     which may contain text and other inline elements 
-->

<define name="Inline">
  <choice>
    <element name="em">
      <interleave>
        <text/>
        <zeroOrMore>
          <ref name="Inline"/>
        </zeroOrMore>
      </interleave>
    </element>  
    <element name="strong">
      <interleave>
        <text/>
        <zeroOrMore>
          <ref name="Inline"/>
        </zeroOrMore>
      </interleave>
    </element>
  </choice>
</define>

<!-- define p element which may contain text with inline elements 
-->
<define name="Paragraph">
  <element name="p">
    <interleave>
      <text/>
      <zeroOrMore>
        <ref name="Inline"/>
      </zeroOrMore>
    </interleave>
  </element>
</define>

<!-- define List reference => ul element and li element. 
     The li element may contain text with inline element, 
     p element and ul element, therefore,
     using Subset ref is appropriate 
-->
<define name="List">
  <element name="ul">
    <oneOrMore>
      <element name="li">
        <ref name="Subset"/> 
      </element>
    </oneOrMore>
  </element>
</define>

</grammar>