I have run across an XML Schema with the following definition:
<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 totalDigits
is redundant. I am somewhat new to XML Schema, and want to make sure I'm not missing something.
What is the actual behavior of totalDigits
vs. maxInclusive
?
Can totalDigits
always be represented with a combination of minInclusive
and MaxInclusive
?
How does totalDigits
affect negative numbers?
can totalDigits always be represented with a combination of minInclusive and 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 minInclusive
and maxInclusive
. If you had decimal values, totalDigits
would tell you how many numbers in total that value could have.
How does totalDigits affect negative numbers?
It is the total number of digits allowed in the number, and is not affected by decimal points, minus signs, etc. From 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With