需要使用XML架构的多个小数位小数

前端之家收集整理的这篇文章主要介绍了需要使用XML架构的多个小数位小数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将数字的小数位数限制为2.

例如 – 1.00有效,但1,1和1.000都无效.

这是一个类似的问题:Specify amount of decimal places of an xs:decimal in an XML schema
这就是答案:

<xs:simpleType name="twoPlacesDecimal" id="twoPlacesDecimal">
    <xs:restriction base="xs:decimal">
        <xs:fractionDigits fixed="true" value="2" />
    </xs:restriction>
</xs:simpleType>

不幸的是,这只将小数位数限制为2,并允许数字为零或一位小数.

解决方法

当我在过去做过这个时,我使用了一个正则表达式匹配器.你可以使用的正则表达式是这样的:

<xsd:simpleType name="exactlyTwoAfterDecimal">
    <xsd:restriction base="xsd:token">
        <xsd:pattern value="^-?\d+\.\d\d$"/>
    </xsd:restriction>
</xsd:simpleType>

猜你在找的XML相关文章