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, ...

Get Using XML with Legacy Business Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.