XSD Numeric Data Types

For the numeric values, the decimal data types are used.

XML Schema built-in data types:

The most common built-in data types of an XML Schema are:

  • xs:string
  • xs:decimal
  • xs:integer
  • xs:boolean
  • xs:date
  • xs:time

Decimal Data Type:

To specify a numeric value, we can use the decimal data type.

Example: Decimal declaration in a schema:

<xs:element name="cost" type="xs:decimal"></xs:element>

An element in a document:

<cost>99.99</cost>

Or:

<cost>+99.3132</cost>

Or:

<cost>-99.3132</cost>

Or:

<cost>0</cost>

Or:

<cost>99</cost>

Integer Data Type:

To specify a numeric value without a fractional component, the integer data type is used.

Example: Integer declaration in a schema:

<xs:element name="cost" type="xs:integer"></xs:element>

An element in a document:

<cost>99</cost>

Or:

<cost>+99</cost>

Or:

<cost>-99</cost>

Or:

<cost>0</cost>

Numeric Data Types:

Except for the decimal itself, all the data types mentioned below are derived from the Decimal data type.

NameUses
byteUsed to define a signed 8-bit integer.
decimalUsed to define a decimal value.
intUsed to define a signed 32-bit integer.
integerUsed to define an integer value.
longUsed to define a signed 64-bit integer.
negativeIntegerUsed to define an integer containing only negative values (..,-2,-1).
nonNegativeIntegerUsed to define an integer containing only non-negative values (0,1,2,..).
nonPositiveIntegerUsed to define an integer containing only non-positive values (..,-2,-1,0).
positiveIntegerUsed to define an integer containing only positive values (1,2,..).
shortUsed to define a signed 16-bit integer.
unsignedLongUsed to define an unsigned 64-bit integer.
unsignedIntUsed to define an unsigned 32-bit integer.
unsignedShortUsed to define an unsigned 16-bit integer.
unsignedByteUsed to define an unsigned 8-bit integer.

Restrictions on Numeric Data Types:

Restrictions used with Numeric data types:

  • enumeration
  • fractionDigits
  • maxExclusive
  • maxInclusive
  • minExclusive
  • minInclusive
  • pattern
  • totalDigits
  • whiteSpace
Content Protection by DMCA.com
Please Share