Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD: What is the difference between xs:integer and xs:int?

Tags:

xsd

I have started to create XSD and found in couple of examples for xs:integer and xs:int.

What is the difference between xs:integer and xs:int? When I should use xs:integer? When I should use xs:int?

like image 207
Michael Avatar asked Oct 13 '22 19:10

Michael


People also ask

What does Xs mean in xsd?

For brevity, the text and examples in this specification use the prefix xs: to stand for this namespace; in practice, any prefix can be used. in the end xs or xsd are only prefixes. XSD is used for example more by Microsoft schemas. The important is how you declare the namespace.

What is integer in XML?

An integer datatype corresponding to W3C XML Schema's xs:integer datatype. An integer number can hold a whole number, but no fraction. Integers may be either signed (allowing negative values) or unsigned (nonnegative values only).

What is int[] xs?

Description. The value space of xs:int is the set of common single size integers (32 bits), i.e., the integers between -2147483648 and 2147483647, its lexical space allows any number of insignificant leading zeros.

What are data types in xsd?

Note: Although they are different data types, xsd:integer , xsd:float , xsd:double , and xsd:decimal all represent numeric values and can be referred as numeric data types.


3 Answers

The difference is the following: xs:int is a signed 32-bit integer. xs:integer is an integer unbounded value. See for details https://web.archive.org/web/20151117073716/http://www.w3schools.com/schema/schema_dtypes_numeric.asp For example, XJC (Java) generates Integer for xs:int and BigInteger for xs:integer.

The bottom line: use xs:int if you want to work cross platforms and be sure that your numbers will pass without a problem. If you want bigger numbers – use xs:long instead of xs:integer (it will be generated to Long).

like image 91
Michael Avatar answered Nov 30 '22 22:11

Michael


The xs:integer type is a restriction of xs:decimal, with the fractionDigits facet set to zero and with a lexical space which forbids the decimal point and trailing zeroes which would otherwise be legal. It has no minimum or maximum value, though implementations running in machines of finite size are not required to be able to accept arbitrarily large or small values. (They are required to support values with 16 decimal digits.)

The xs:int type is a restriction of xs:long, with the maxInclusive facet set to 2147483647 and the minInclusive facet to -2147483648. (As you can see, it will fit conveniently into a two-complement 32-bit signed-integer field; xs:long fits in a 64-bit signed-integer field.)

The usual rule is: use the one that matches what you want to say. If the constraint on an element or attribute is that its value must be an integer, xs:integer says that concisely. If the constraint is that the value must be an integer that can be expressed with at most 32 bits in twos-complement representation, use xs:int. (A secondary but sometimes important concern is whether your tool chain works better with one than with the other. For data that will live longer than your tool chain, it's wise to listen to the data first; for data that exists solely to feed the tool chain, and which will be of no interest if you change your tool chain, there's no reason not to listen to the tool chain.)

like image 27
C. M. Sperberg-McQueen Avatar answered Nov 30 '22 22:11

C. M. Sperberg-McQueen


I would just add a note of pedantry that may be important to some people: it's not correct to say that xs:int "is" a signed 32-bit integer. That form of words implies an implementation in memory (or registers, etc) within a binary digital computer. XML is character-based and would implement the maximum 32-bit signed value as "2147483647" (my quotes, of course), which is a lot more than 32 bits! What IS true is that xs:int is (indirectly) a restriction of xs:integer which sets the maximum and minimum allowed values to be the same as the corresponding implementation-imposed limits of a 32-bit integer with a sign bit.

like image 29
PeteCahill Avatar answered Nov 30 '22 23:11

PeteCahill