XSD 架构:如何指定值中的位数?

发布于 2024-10-03 14:29:34 字数 1401 浏览 1 评论 0原文

我想将元素中允许的位数限制为 6:

<AccountNumber>123456</AccountNumber>
<AccountNumber>999999</AccountNumber>
<AccountNumber>000000</AccountNumber>

字段格式规范为 6 位、零填充的数字。

我读到我可能想使用 totalDigits 限制,基于:

totalDigits 指定允许的确切位数。必须大于零

所以我有简单的类型:

<xs:simpleType name="AccountNumber">
   <xs:restriction base="xs:int">
      <xs:totalDigits value="6"/>
   </xs:restriction>
</xs:simpleType>

虽然它捕获无效数字,例如:

<AccountNumber>1234567</AccountNumber>
<AccountNumber>0000000</AccountNumber>
<AccountNumber></AccountNumber>

它不捕获无效数字:

<AccountNumber>12345</AccountNumber>
<AccountNumber>01234</AccountNumber>
<AccountNumber>00123</AccountNumber>
<AccountNumber>00012</AccountNumber>
<AccountNumber>00001</AccountNumber>
<AccountNumber>00000</AccountNumber>
<AccountNumber>0000</AccountNumber>
<AccountNumber>000</AccountNumber>
<AccountNumber>00</AccountNumber>
<AccountNumber>0</AccountNumber>

指定允许的确切位数的建议限制是什么?

i want to limit the number of digits allowed in an element to 6:

<AccountNumber>123456</AccountNumber>
<AccountNumber>999999</AccountNumber>
<AccountNumber>000000</AccountNumber>

The field format specification is 6-digit, zero-padded, numeric.

i read that i might want to use the totalDigits restriction, based on:

totalDigits Specifies the exact number of digits allowed. Must be greater than zero

So i have the simple type:

<xs:simpleType name="AccountNumber">
   <xs:restriction base="xs:int">
      <xs:totalDigits value="6"/>
   </xs:restriction>
</xs:simpleType>

And while it catches invalid numbers, such as:

<AccountNumber>1234567</AccountNumber>
<AccountNumber>0000000</AccountNumber>
<AccountNumber></AccountNumber>

it doesn't catch invalid numbers:

<AccountNumber>12345</AccountNumber>
<AccountNumber>01234</AccountNumber>
<AccountNumber>00123</AccountNumber>
<AccountNumber>00012</AccountNumber>
<AccountNumber>00001</AccountNumber>
<AccountNumber>00000</AccountNumber>
<AccountNumber>0000</AccountNumber>
<AccountNumber>000</AccountNumber>
<AccountNumber>00</AccountNumber>
<AccountNumber>0</AccountNumber>

What is a suggested restriction to specify the exact number of digits allowed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

被翻牌 2024-10-10 14:29:34

您需要使用 xs:pattern 并提供正则表达式将其限制为一个数字。

<xs:simpleType name="AccountNumber">
   <xs:restriction base="xs:int">
      <xs:pattern value="\d{6}"/>
   </xs:restriction>
</xs:simpleType>

You need to use xs:pattern and provide a regular expression to limit it to a number.

<xs:simpleType name="AccountNumber">
   <xs:restriction base="xs:int">
      <xs:pattern value="\d{6}"/>
   </xs:restriction>
</xs:simpleType>
泪意 2024-10-10 14:29:34

我可能会使用 xs:minInclusivexs:maxInclusive

I would probably use xs:minInclusive and xs:maxInclusive.

灼疼热情 2024-10-10 14:29:34

这是最简单的方法

    <xs:element name="prodid">
     <xs:simpleType>
      <xs:restriction base="xs:integer">
       <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
      </xs:restriction>
     </xs:simpleType>
    </xs:element> 

This is the simplest way

    <xs:element name="prodid">
     <xs:simpleType>
      <xs:restriction base="xs:integer">
       <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
      </xs:restriction>
     </xs:simpleType>
    </xs:element> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文