XSD 架构:如何指定值中的位数?
我想将元素中允许的位数限制为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用
xs:pattern
并提供正则表达式将其限制为一个数字。You need to use
xs:pattern
and provide a regular expression to limit it to a number.我可能会使用 xs:minInclusive 和 xs:maxInclusive。
I would probably use xs:minInclusive and xs:maxInclusive.
这是最简单的方法
This is the simplest way