Making New Types

<<< Here's the <temperature> part of the weather report:

  <temperature>
     <min>20</min>
     <max>29</max>
     <forecast-low>21</forecast-low>
     <forecast-high>30</forecast-high>
  </temperature>

A <temperature> has four sub-elements. We want them all to be within a reasonable range of Celsius temperatures. Rather than typing the information into our schema four times, we'll create a new simple type called DegreeRange as follows:

    <simpleType name="DegreeRange" base="decimal">
        <minInclusive value="-70"/>
        <maxInclusive value="80"/>
    </simpleType>

Once this is defined, we can use it just as if it were one of the built-in types like decimal or string.

    <element name="temperature">
        <complexType>
            <element name="min" type="ewe:DegreeRange"/>
            <element name="max" type="ewe:DegreeRange"/>
            <element name="forecast-low" type="ewe:DegreeRange"/>
            <element name="forecast-high" type="ewe:DegreeRange"/>
        </complexType>
    </element>

It's necessary to prefix the DegreeRange with ewe:, since that type belongs to the new markup language, not to the XML Schema markup language.

Now, we need only define the <wind> portion of the weather report. >>>

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