如何定义 XML XSD 类型来描述 "double" 的子集,不包括 "NaN" 、"positiveInfinity"、"negativeInfinity"
How can I define an XML XSD type to describe the subset of "double" excluding "NaN" ,"positiveInfinity", "negativeInfinity"
我有一个现有的 XSD,其中元素的类型指定为 "double",根据 spec,这将有效值限制为:
1) the non-zero numbers m × 2e , where m is an integer whose absolute value is less than 253, and e is an integer between −1074 and 971, inclusive.
2) In addition to these values, the ·value space· of double also contains the following ·special values·: positiveZero, negativeZero, positiveInfinity, negativeInfinity, and notANumber.
我对第一部分没问题,但我想 disallow/exclude 以下内容:
- positiveInfinity
- negativeInfinity
- notANumber (NaN)
什么是 XML XSD syntax/definition 来定义这个新类型,表示“double,positiveInfinity、negativeInfinity、notANumber (NaN) 除外”。
你可以用 restriction
<xs:element name="myDouble">
<xs:simpleType>
<xs:restriction base="xs:double">
<xs:minExclusive value="-INF"/>
<xs:maxExclusive value="INF"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
注意 : NaN 似乎也被 <xs:maxExclusive value="INF"/>
停止了
ERROR: Element 'myDouble': [facet 'maxExclusive'] The value 'NaN' must
be less than 'INF'.
我已经试过了,它适用于
<myDouble>123.456</myDouble> <!-- OK -->
<myDouble>+1234.456</myDouble> <!-- OK -->
<myDouble>-1.2344e56</myDouble> <!-- OK -->
<myDouble>-.45E-6</myDouble> <!-- OK -->
<myDouble>INF</myDouble> <!-- KO -->
<myDouble>-INF</myDouble> <!-- KO -->
<myDouble>NaN</myDouble> <!-- KO -->
我有一个现有的 XSD,其中元素的类型指定为 "double",根据 spec,这将有效值限制为:
1) the non-zero numbers m × 2e , where m is an integer whose absolute value is less than 253, and e is an integer between −1074 and 971, inclusive. 2) In addition to these values, the ·value space· of double also contains the following ·special values·: positiveZero, negativeZero, positiveInfinity, negativeInfinity, and notANumber.
我对第一部分没问题,但我想 disallow/exclude 以下内容:
- positiveInfinity
- negativeInfinity
- notANumber (NaN)
什么是 XML XSD syntax/definition 来定义这个新类型,表示“double,positiveInfinity、negativeInfinity、notANumber (NaN) 除外”。
你可以用 restriction
<xs:element name="myDouble">
<xs:simpleType>
<xs:restriction base="xs:double">
<xs:minExclusive value="-INF"/>
<xs:maxExclusive value="INF"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
注意 : NaN 似乎也被 <xs:maxExclusive value="INF"/>
ERROR: Element 'myDouble': [facet 'maxExclusive'] The value 'NaN' must be less than 'INF'.
我已经试过了,它适用于
<myDouble>123.456</myDouble> <!-- OK -->
<myDouble>+1234.456</myDouble> <!-- OK -->
<myDouble>-1.2344e56</myDouble> <!-- OK -->
<myDouble>-.45E-6</myDouble> <!-- OK -->
<myDouble>INF</myDouble> <!-- KO -->
<myDouble>-INF</myDouble> <!-- KO -->
<myDouble>NaN</myDouble> <!-- KO -->