加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 23:08:07 所属栏目:百科 来源:网络整理
导读:我正在创建 XML Schema,我的一个值是一年.因此,我想确保所有值都有4个字符.为此,我使用以下语法: xs:element name="publish_year" maxOccurs="1" xs:simpleType xs:restriction base="xs:positiveInteger" xs:totalDigits value="4"/ /xs:restriction /xs:s
我正在创建 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]dd|[2]ddd)$"/>
    </xs:restriction>
</xs:simpleType>

解决方法

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

(minInclusive – maxInclusive)

例如 ?

<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" />

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读