xs:int

Converts $string-var (a string) to an int value.

If the value of $string-var is greater than 2,147,483,647 or less than -2,147,483,648, the following error is produced:

Error occurred while executing XQuery: Could not cast "2147483649" to type [int@http://www.w3.org/2001/XMLSchema] 

Note: The value $string-var must be specified without commas as shown in the following example invocation:

xs:int("999999999")

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:int(xs:string $string-var) —> xs:int

Arguments

Data Type
Argument
Description

xs:string

$string-var

Represents the string to convert to an int value.

Returns

Returns the int value of $string-var.

Examples

Simple

Invoking int("10403")returns the integer value 10403 as shown in the following example query:

<int>{xs:int("10403")}</int> 

The preceding query generates the following result:

<int>10403</int> 

Error—Decimal Point Not Allowed

Invoking int("104.0")outputs an error because 104.0 not a valid integer (decimal point is not allowed.)

For example, the following example query:

<int>{xs:int("104.0")}</int> 
Produces the following error: 
Error occurred while executing XQuery: Could not cast "104.0" to type [int@http://www.w3.org/2001/XMLSchema] 

Error—Not a Number

Invoking int("foo")outputs an error because "foo" is not a number.

For example, the following example query:

<int>{xs:int("foo")}</int> 
Produces the following error: 
Error occurred while executing XQuery: Could not cast "foo" to type [int@http://www.w3.org/2001/XMLSchema] 

Null

Invoking int(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<int>{xs:int(())}</int> 

The preceding query generates the following result:

<int/> 

Related Topics

W3C int data type description