Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema XSD TotalDigits vs. MaxInclusive

Tags:

xml

xsd

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?

like image 452
Nathan Avatar asked Oct 03 '08 19:10

Nathan


2 Answers

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.

like image 58
ConroyP Avatar answered Sep 22 '22 03:09

ConroyP


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.

like image 45
Wes P Avatar answered Sep 26 '22 03:09

Wes P