Restriction in XML Schema
I need to place a restriction on an integer that can take values between 1 and 48, but can also take the single value of 63. Can this be done?
I know the following will take care of the first restriction, but how can I add 63 to the list?
<xs:simpleType name="nameId">
<xs:element name="id">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1开发者_运维百科"/>
<xs:maxInclusive value="48"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:simpleType>
Define two types: one allows an integer in the range 1-48, and one that only allows the integer 64; then define a type that is the union of these two.
Or in XSD 1.1, just define a type that restricts xs:integer with the facet
<assert test="$value=(1 to 48, 64)"/>
Instead of using an integer base you could use a RegEx?
For example this would almost work but it has a caveat....
<xs:simpleType name="nameId">
<xs:element name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([1-4]{1}\d|63)"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:simpleType>
Hope this helps
In your case you can simply use enumeration with all values you need and have base as integer
<xs:restriction base="xs:integer">
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="3"/>
<xs:enumeration value="4"/>
<xs:enumeration value="5"/>
<xs:enumeration value="6"/>
<xs:enumeration value="7"/>
<xs:enumeration value="8"/>
<xs:enumeration value="9"/>
<xs:enumeration value="10"/>
<xs:enumeration value="11"/>
<xs:enumeration value="12"/>
<xs:enumeration value="13"/>
<xs:enumeration value="14"/>
<xs:enumeration value="15"/>
<xs:enumeration value="16"/>
<xs:enumeration value="17"/>
<xs:enumeration value="18"/>
<xs:enumeration value="19"/>
<xs:enumeration value="20"/>
<xs:enumeration value="21"/>
<xs:enumeration value="22"/>
<xs:enumeration value="23"/>
<xs:enumeration value="24"/>
<xs:enumeration value="25"/>
<xs:enumeration value="26"/>
<xs:enumeration value="27"/>
<xs:enumeration value="28"/>
<xs:enumeration value="29"/>
<xs:enumeration value="30"/>
<xs:enumeration value="31"/>
<xs:enumeration value="32"/>
<xs:enumeration value="33"/>
<xs:enumeration value="34"/>
<xs:enumeration value="36"/>
<xs:enumeration value="36"/>
<xs:enumeration value="37"/>
<xs:enumeration value="38"/>
<xs:enumeration value="39"/>
<xs:enumeration value="40"/>
<xs:enumeration value="41"/>
<xs:enumeration value="42"/>
<xs:enumeration value="43"/>
<xs:enumeration value="44"/>
<xs:enumeration value="45"/>
<xs:enumeration value="46"/>
<xs:enumeration value="47"/>
<xs:enumeration value="48"/>
<xs:enumeration value="63"/>
</xs:restriction>
精彩评论