【问题标题】:How to set <xsd:minInclusive> decimal value?如何设置 <xsd:minInclusive> 十进制值?
【发布时间】:2016-02-11 16:51:05
【问题描述】:

我想将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。

【问题讨论】:

  • 请展示完整的 XML Schema 文档并解释“但失败”的含义。求助:stackoverflow.com/help/mcve.
  • 我对它进行了验证。当 如果我们给出值 0 ,它会抛出验证。我的要求是如果值小于或等于 0 ,我需要进行验证。
  • “我有验证”是什么意思?

标签: xml xsd xsd-validation xsd.exe


【解决方案1】:

如果您真的想允许等于或大于 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-10
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    相关资源
    最近更新 更多