How to define an integer range in XML / XSD?

Viewed 2180

I currently have this in an XSD:

<xs:element name="qty" maxOccurs="1" minOccurs="1" />

How can I add a rule that also only allows the value of Qty to be between 100 to 2000?

1 Answers

Use xs:restriction with xs:{min|max}{In|Ex}clusive:

  <xs:simpleType name="Quantity100to2000">
    <xs:restriction base="xs:integer">
      <xs:minExclusive value="100"/>
      <xs:maxExclusive value="2000"/>
    </xs:restriction> 
  </xs:simpleType>

  <xs:element name="qty" maxOccurs="1" minOccurs="1" type="Quantity100to2000"/>
Related