xs:byte

Converts $string-var (a string) to a byte value.

If the value of $string-var is greater than 127 or less than -128, the following error is produced:

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

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:byte(xs:string $string-var) —> xs:byte

Arguments

Data Type
Argument
Description

xs:string

$string-var

Represents the string to convert to a byte.

Returns

Returns the byte value of $string-var.

Examples

Simple

Invoking byte("104")returns the integer value 104 as shown in the following example query:

<byte>{xs:byte("104")}</byte> 

The preceding query generates the following result:

<byte>104</byte> 

Error—Decimal Point Not Allowed

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

For example, the following example query:

<byte>{xs:byte("104.0")}</byte> 

Produces the following error:

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

Error—Not a Number

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

For example, the following example query:

<byte>{xs:byte("foo")}</byte> 

Produces the following error:

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

Null

Invoking byte(()) 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:

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

The preceding query generates the following result:

<byte/> 

Related Topics

W3C byte data type description