Making Validation More Specific

<<< As it stands, our specification for a valid <station> isn't as precise as we'd like. A latitude must be between -90 and 90, and a longitude between -180 and 180. Weather station abbreviations are exactly four letters long, and we'd like to restrict the weather station's full name to seventy-five characters. We do this by adding type specifications to the schema:

    <element name="station">
        <complexType>
            <element name="latitude">
                <simpleType base="decimal">
                    <minInclusive value="-180"/>
                    <maxInclusive value="180"/>
                </simpleType>
            </element>
            <element name="longitude" type="decimal">
                <simpleType base="decimal">
                    <minInclusive value="-90"/>
                    <maxInclusive value="90"/>
                </simpleType>
            </element>
            <attribute name="fullname">
                <simpleType base="string">
                    <maxLength value="75"/>
                </simpleType>
            </attribute>
            <attribute name="abbrev">
                <simpleType base="string">
                    <length value="4"/>
                </simpleType>
            </attribute>
       </complexType>
   </element>

This specification of a <station> is fairly lengthy. There are some ways to make our XML Schema more modular and compact, as we will see when we continue with the <temperature> element. >>>

  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