XML Schema XSD TotalDigits 与 MaxInclusive
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/168402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML Schema XSD TotalDigits vs. MaxInclusive
提问by Nathan
I have run across an XML Schema with the following definition:
我遇到了具有以下定义的 XML 模式:
<xs:simpleType name="ClassRankType">
<xs:restriction base="xs:integer">
<xs:totalDigits value="4"/>
<xs:minInclusive value="1"/>
<xs:maxInclusive value="9999"/>
</xs:restriction>
</xs:simpleType>
However, it seems to me that totalDigitsis redundant. I am somewhat new to XML Schema, and want to make sure I'm not missing something.
然而,在我看来,这totalDigits是多余的。我对 XML Schema 有点陌生,希望确保我没有遗漏任何东西。
What is the actual behavior of totalDigitsvs. maxInclusive?
totalDigitsvs.的实际行为是maxInclusive什么?
Can totalDigitsalways be represented with a combination of minInclusiveand MaxInclusive?
可以totalDigits始终与的组合来表示minInclusive和MaxInclusive?
How does totalDigitsaffect negative numbers?
如何totalDigits影响负数?
采纳答案by ConroyP
can totalDigits always be represented with a combination of minInclusive and MaxInclusive?
totalDigits 总是可以用 minInclusive 和 MaxInclusive 的组合来表示吗?
In this case, yes. As you're dealing with an integer, the value must be a whole number, so you have a finite set of values between minInclusiveand maxInclusive. If you had decimal values, totalDigitswould tell you how many numbers in total that value could have.
在这种情况下,是的。当您处理一个整数时,该值必须是一个整数,因此您在minInclusive和之间有一组有限的值maxInclusive。如果您有十进制值,totalDigits则会告诉您该值总共可以有多少个数字。
How does totalDigits affect negative numbers?
totalDigits 如何影响负数?
It is the total number of digits allowed in the number, and is not affected by decimal points, minus signs, etc. From auxy.com:
它是数字中允许的总位数,不受小数点、减号等的影响。来自auxy.com:
The number specified by the value attribute of the
<xsd:totalDigits>facet will restrict the total number of digits that are allowed in the number, on both sides of the decimal point.
<xsd:totalDigits>facet的 value 属性指定的数字将限制数字中允许的总位数,小数点两侧。
回答by Wes P
totalDigits is the total number of digits the number can have, including decimal numbers. So a totalDigits of 4 would allow 4.345 or 65.43 or 932.1 or a 4 digit whole integer as in the example above. Same for negative. Any of those previous examples can all be made negative and still validate as a totalDigits of 4.
totalDigits 是数字可以具有的总位数,包括十进制数。因此,totalDigits 为 4 将允许 4.345 或 65.43 或 932.1 或 4 位整数整数,如上例所示。负数也一样。前面的任何示例都可以设为负数,并且仍然验证为 totalDigits 为 4。
max and min inclusive/exclusive limit the range of the numbers. The maxinclusive might seem be a little redundant in your example, but the mininclusive makes certain the number is greater than 0.
max 和 min 包含/不包含限制了数字的范围。在您的示例中, maxinclusive 可能看起来有点多余,但 mininclusive 确保数字大于 0。

