2010-10-04 136 views
3

我想检查我的XML中的字段是否为positive double/decimal。 XSD中有一个type="xs:positiveInteger"数据类型,但没有正的双精度或小数。有没有办法通过定义自定义数据类型或其他方式来实现这一点?如何在xsd中定义自定义数据类型?

回答

4
<xs:element name="data"> 
    <xs:simpleType> 
    <xs:restriction base="xs:float"> 
     <xs:minInclusive value="0"/> 
    </xs:restriction> 
    </xs:simpleType> 
</xs:element> 

我认为这应该做到这一点。可能有一个更短的方式,我仍然在学习xsd。

+0

我宁愿在这种情况下使用base而不是float。 – YoK 2010-10-04 08:48:04

+0

我想说你已经学会了那一点XSD :)。给出原始问题,xs:float或xs:decimal都可以工作。 – 2010-10-04 13:04:41

+0

至少根据http://www.w3schools.com/xml/schema_dtypes_numeric.asp,没有'float'类型 – 2016-06-16 21:33:36

3

您可以通过定义带限制的十进制数据类型来实现这一点,如下所示。

<xs:simpleType name="positiveDecimal"> 
    <xs:restriction base="xs:decimal"> 
    <xs:minInclusive value="0"/> 
    </xs:restriction> 
</xs:simpleType>