user3014074
user3014074

Reputation: 21

How to restrict an element value being lower than another in XML Schema?

I needed to have a restriction on an element. Given two elements like:

<xs:element name="lowerValue" type="xs:int" minOccurs="0" maxOccurs="1" />
     <xs:element name="higgerValue" type="xs:int" minOccurs="0" maxOccurs="1"> 
          <xs:simpleType>
               <xs:restriction base="xs:string">
                      <xs:minLength value= lowerValue />
               </xs:restriction>
          </xs:simpleType>
</xs:element>

In higgerValue needed to restrict the value to be no lower than lowerValue.

It is possible? How do I can do set the minimun value accepted the value of another element?

Upvotes: 0

Views: 128

Answers (1)

Michael Kay
Michael Kay

Reputation: 163418

In XSD 1.1 you can define an assertion. The assertion goes on the containing element (let's say container is the parent of both lowerValue and higherValue). Then on the definition of element container, you can write <xs:assert test="higherValue gt lowerValue"/>.

Cross-element constraints aren't possible in XSD 1.0.

Upvotes: 1

Related Questions