XSD datatype
xs:int
A signed 32-bit integer: −2,147,483,648 to 2,147,483,647. The bounded type most schemas should use and most do not.
xs:int carries the range of a signed 32-bit integer, and xs:long the range of a signed 64-bit one. Both are derived from xs:integer by fixing minInclusive and maxInclusive.
Choosing xs:int over xs:integer moves an overflow from a runtime surprise to a validation error, which is where you want it.
- Lexical space
- Optional sign, then digits, within the 32-bit signed range.
- Derives from
xs:long- Category
- Numeric types
- Facets
- minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, whiteSpace, totalDigits, fractionDigits
What catches people out
- The bounds are inclusive and asymmetric: the minimum is one further from zero than the maximum.
- xs:int is 32-bit and xs:long is 64-bit. Neither is named after the number of bits, which catches people coming from C.
- A value one past the boundary is a validation error, which is the entire reason to use this type rather than xs:integer.
The schema used
This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="v" type="xs:int"/>
</xs:schema>Related
- xs:integerA whole number of unlimited size. It derives from xs:decimal, not from a machine int — so it has no range at all.
- xs:unsignedIntAn unsigned 32-bit integer: 0 to 4,294,967,295.
- xs:decimalAn exact decimal number with arbitrary precision — and no exponent notation, which is the usual reason a value is rejected.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.