微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在XML Schema中为整数设置最小长度?

我正在创建 XML Schema,我的一个值是一年.因此,我想确保所有值都有4个字符.为此,我使用以下语法:

<xs:element name="publish_year" maxOccurs="1">
  <xs:simpleType>
    <xs:restriction base="xs:positiveInteger">
      <xs:totalDigits value="4"/>
    </xs:restriction>
  </xs:simpleType>                                      
</xs:element>

如果我正确理解“totalDigits”,有人可以传入“publish_year”值“2008”或“200”.两者都有效.因此,如何构建我的XSD以确保需要4位数?乍一看,我猜我会使用正则表达式,但我想知道我是否忽略了已经出现过的东西(比如“totalDigits”)

更新:

我选择了以下解决方案.它可能有点矫枉过正,但它得到了重点:

<xs:simpleType>
    <xs:restriction base="xs:positiveInteger">
        <xs:totalDigits value="4" fixed="true"/>
        <xs:minInclusive value="1900"/>
        <xs:pattern value="^([1][9]\d\d|[2]\d\d\d)$"/>
    </xs:restriction>
</xs:simpleType>

解决方法

如果将价值作为附加限制呢?

(minInclusivemaxInclusive)

例如 ?

<xs:minInclusive value="1900"/> et <xs:maxInclusive value="2008"/>

但是为了回到totalDigits约束,为什么不将fixed属性设置为true?

If {fixed} is true,then types for which the current type is the {base type deFinition} cannot specify a value for totalDigits other than {value}.

<xs:totalDigits value="4" fixed="true" />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。