如何设置<xsd:mininclusive>十进制值?

时间:2016-02-11 16:51:05

标签: xml xsd xsd-validation xsd.exe

我想将minInclusive设置为0.01。我试过下面但是失败了。

<xs:simpleType name="WeightType">
    <xs:restriction base="xs:decimal">
        <xs:totalDigits value="5"/>
        <xs:fractionDigits value="2"/>
        <xs:minInclusive value="0.01"/>
    </xs:restriction>
</xs:simpleType>

有人可以建议怎么写吗?

如果不可能,还有其他方法可以实现吗? 我的要求是字段应该大于0。

1 个答案:

答案 0 :(得分:4)

如果您确实希望允许值等于0.01或更高,那么您的xs:simpleType就可以了。

但是,如果您的真正要求是将值限制为大于零,而不是

  <xs:minInclusive value="0.01"/>

你可以简单地使用

  <xs:minExclusive value="0"/>

由于您仍然遇到问题,请让我们非常完整和彻底......

此XSD,

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="w" type="WeightType"/>

  <xs:simpleType name="WeightType">
    <xs:restriction base="xs:decimal">
      <xs:totalDigits value="5"/>
      <xs:fractionDigits value="2"/>
      <xs:minExclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

不会验证这些XML实例

<w>-0.1</w>
<w>0</w>

验证这些XML实例:

<w>1</w>
<w>0.1</w>
<w>0.01</w>