Setting Minimum and Maximum Values

Just as people want schemas to prevent them from truncating alphanumeric fields, they also want schemas to set upper limits on numeric fields so they don't cause truncations or overflows. Using our working example, we could restrict the zip code to a set of values as follows:

Setting Maximum and Minimum Values
<xs:simpleType name="zipCodeType">
  <xs:annotation>
    <xs:documentation>Here we define a ZIP Code as an integer
        from 1 through 99999
    </xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="1"/>
    <xs:maxInclusive value="99999"/>
  </xs:restriction>
</xs:simpleType>

This type of minimum and maximum value restriction probably makes more sense for the amount due on an invoice, but you get the idea. The next subsection shows a better way to do it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset