Xml XSD模式:如何指定值中的位数?
我想将元素中允许的位数限制为6:Xml XSD模式:如何指定值中的位数?,xml,xsd,xsd-validation,Xml,Xsd,Xsd Validation,我想将元素中允许的位数限制为6: <AccountNumber>123456</AccountNumber> <AccountNumber>999999</AccountNumber> <AccountNumber>000000</AccountNumber> 当它捕获无效数字时,例如: <AccountNumber>1234567</AccountNumber> <AccountNumber
<AccountNumber>123456</AccountNumber>
<AccountNumber>999999</AccountNumber>
<AccountNumber>000000</AccountNumber>
当它捕获无效数字时,例如:
<AccountNumber>1234567</AccountNumber>
<AccountNumber>0000000</AccountNumber>
<AccountNumber></AccountNumber>
1234567
0000000
它不会捕获无效的数字:
<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>
12345
01234
00123
00012
00001
00000
0000
000
00
0
指定允许的确切位数的建议限制是什么?您需要使用并提供一个正则表达式将其限制为一个数字
<xs:simpleType name="AccountNumber">
<xs:restriction base="xs:int">
<xs:pattern value="\d{6}"/>
</xs:restriction>
</xs:simpleType>
我可能会使用和。这是最简单的方法
<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>
。。。需要一段时间才能通知其他答案已经发布。我相信这些答案是根据数值而不是位数来限制的。如果minInclusive是7,则表示值为7,而不是7位。@Jeff-您认为1000000的minInclusive
是7位吗?9999999的maxExclusive
也是七位数字吗?@Anon:这是一种有点狡猾的方法来强制执行长度。态度不错@杰夫:耸耸肩:黑客就是你找到他们的地方。对我来说,用数字限制以外的任何方法约束整数值都是一个难题。另一方面,字符串值受到正则表达式的适当约束。我的观点是OP的数据类型是个问题。我正要说,“你可以使用带有xs:int
的模式吗?那怎么样。”@Ian:是的,我也有点惊讶。回答这个问题我学到了一些东西。总是乐于助人。
<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>