I want to write an XML Schema with an constraint for intgegers. The interger should only be valid with a certain increment.
The basic element could be something like this:
<xs:element name="MotorFrequency">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1" />
<xs:maxInclusive value="2000000" />
</xs:restriction>
</xs:simpleType>
</xs:element>
I need a constraint that only allows an interger with an 4000 increment, like 4000, 8000, 12000 etc.
How can I achieve that?
Only with XSD 1.1 , you could use an <xs:assertion>
:
<xs:element name="MotorFrequency">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1" />
<xs:maxInclusive value="2000000" />
<xs:assertion test="($value mod 4000) = 0"></xs:assertion>
</xs:restriction>
</xs:simpleType>
</xs:element>
That way, an error will be raised if assertion fails.
If you're stuck with XSD 1.0, then you could write a regular expression
value="[0-9]*(([02468][048])|([13579][26])000"
Not tested.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.