XSD datatype
xs:integer
A whole number of unlimited size. It derives from xs:decimal, not from a machine int — so it has no range at all.
xs:integer is xs:decimal with fractionDigits fixed at 0. That derivation is the surprise: it inherits arbitrary precision, so there is no upper or lower bound. A 50-digit integer is valid.
If you need a bounded value, the derived types xs:int, xs:long, xs:short and xs:byte carry the ranges their names imply.
- Lexical space
- Optional sign, then one or more digits. No decimal point.
- Derives from
xs:decimal- Category
- Numeric types
- Facets
- minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, whiteSpace, totalDigits, fractionDigits
What validates
Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.
42-7+012345678901234567890123456789012345678901234567890
What does not
3.0A decimal point is not allowed, even when the value is whole.
1e3No exponent notation.
0x1FOnly decimal digits.
What catches people out
- Unbounded. xs:integer will happily validate a number no 64-bit type can hold, and the failure will happen in your code rather than in validation.
- '3.0' is not an xs:integer even though it is a whole number. The lexical form matters, not just the value.
- For a bounded field use xs:int (32-bit) or xs:long (64-bit) and let validation catch overflow.
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:integer"/>
</xs:schema>Related
- xs:decimalAn exact decimal number with arbitrary precision — and no exponent notation, which is the usual reason a value is rejected.
- xs:intA 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:positiveIntegerAn integer of 1 or more. Zero is not positive, which is the distinction from xs:nonNegativeInteger.
- xs:nonNegativeIntegerAn integer of 0 or more. The right type for counts, where zero is a real answer.
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.