Difference between revisions of "Conversion Module"
Jump to navigation
Jump to search
(→Dates) |
|||
Line 147: | Line 147: | ||
=Dates= | =Dates= | ||
− | ==convert: | + | ==convert:ms-to-dateTime== |
{| | {| | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|convert: | + | |{{Func|convert:ms-to-dateTime|$number as xs:integer|xs:dateTime}}<br /> |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Converts the specified | + | |Converts the specified {{Code|$number}} of milliseconds since 1 Jan 1970 to a dateTime item.<br /> |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * {{Code|convert: | + | * {{Code|convert:ms-to-dateTime(0)}} returns {{Code|1970-01-01T00:00:00Z}}. |
− | * {{Code|convert: | + | * {{Code|convert:ms-to-dateTime(1234567890123)}} returns {{Code|2009-02-14T00:31:30.123Z}}. |
|} | |} | ||
− | ==convert:dateTime-to- | + | ==convert:dateTime-to-ms== |
{| | {| | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|convert:dateTime-to- | + | |{{Func|convert:dateTime-to-ms|$dateTime as xs:dateTime|xs:integer}}<br /> |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Converts the specified | + | |Converts the specified {{Code|$dateTime}} to number of milliseconds since 1 Jan 1970.<br /> |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * {{Code|convert:dateTime-to- | + | * {{Code|convert:dateTime-to-ms(xs:dateTime('1970-01-01T00:00:00Z'))}} returns {{Code|0}}. |
|} | |} | ||
Revision as of 01:31, 14 August 2012
This XQuery Module contains functions to convert data between different formats.
Conventions
All functions in this module are assigned to the http://basex.org/modules/convert
namespace, which is statically bound to the convert
prefix.
All errors are assigned to the http://basex.org/errors
namespace, which is statically bound to the bxerr
prefix.
Strings
convert:binary-to-string
Signatures | convert:binary-to-string($bytes as basex:binary) as xs:string convert:binary-to-string($bytes as basex:binary, $encoding as xs:string) as xs:string
|
Summary | Converts the specifed binary data (xs:base64Binary, xs:hexBinary) to a string. The UTF-8 default encoding can be overwritten with the optional $encoding argument.
|
Errors | BXCO0001 : The input is an invalid XML string, or the wrong encoding has been specified.BXCO0002 : The specified encoding is invalid or not supported.
|
Examples |
|
convert:string-to-base64
Signatures | convert:string-to-base64($input as xs:string) as xs:base64Binary convert:string-to-base64($input as xs:string, $encoding as xs:string) as xs:base64Binary
|
Summary | Converts the specified string to a xs:base64Binary item. If the default encoding is chosen, conversion will be cheap, as both xs:string and xs:base64Binary items are internally represented as byte arrays.The UTF-8 default encoding can be overwritten with the optional $encoding argument.
|
Errors | BXCO0001 : The input cannot be represented in the specified encoding.BXCO0002 : The specified encoding is invalid or not supported.
|
Examples |
|
convert:string-to-hex
Signatures | convert:string-to-hex($input as xs:string) as xs:hexBinary convert:string-to-hex($input as xs:string, $encoding as xs:string) as xs:hexBinary
|
Summary | Converts the specified string to a xs:hexBinary item. If the default encoding is chosen, conversion will be cheap, as both xs:string and xs:hexBinary items are internally represented as byte arrays.The UTF-8 default encoding can be overwritten with the optional $encoding argument.
|
Errors | BXCO0001 : The input cannot be represented in the specified encoding.BXCO0002 : The specified encoding is invalid or not supported.
|
Examples |
|
Byte Arrays
convert:bytes-to-base64
Signatures | convert:bytes-to-base64($input as xs:byte*) as xs:base64Binary
|
Summary | Converts the specified byte sequence to a xs:base64Binary item. Conversion is cheap, as xs:base64Binary items are internally represented as byte arrays.
|
Errors | BXCO0001 : The input cannot be represented in the specified encoding.BXCO0002 : The specified encoding is invalid or not supported.
|
Examples |
|
convert:bytes-to-hex
Signatures | convert:string-to-hex($input as xs:byte*) as xs:hexBinary
|
Summary | Converts the specified byte sequence to a xs:hexBinary item. Conversion is cheap, as xs:hexBinary items are internally represented as byte arrays.
|
Errors | BXCO0001 : The input cannot be represented in the specified encoding.BXCO0002 : The specified encoding is invalid or not supported.
|
Examples |
|
convert:binary-to-bytes
Signatures | convert:binary-to-bytes($bin as basex:binary) as xs:byte*
|
Summary | Returns the specified binary data (xs:base64Binary, xs:hexBinary) as a sequence of bytes. |
Examples |
|
Numbers
convert:integer-to-base
Signatures | convert:integer-to-base($num as xs:integer, $base as xs:integer) as xs:string |
Summary | Converts $num to base $base , interpreting it as a 64-bit unsigned integer.The first $base elements of the sequence '0',..,'9','a',..,'z' are used as digits.Valid bases are 2, .., 36 . |
Examples |
|
convert:integer-from-base
Signatures | convert:integer-from-base($str as xs:string, $base as xs:integer) as xs:integer |
Summary | Decodes an xs:integer from $str , assuming that it's encoded in base $base .The first $base elements of the sequence '0',..,'9','a',..,'z' are allowed as digits, case doesn't matter. Valid bases are 2 - 36. If $str contains more than 64 bits of information, the result is truncated arbitarily.
|
Examples |
|
Dates
convert:ms-to-dateTime
Signatures | convert:ms-to-dateTime($number as xs:integer) as xs:dateTime |
Summary | Converts the specified $number of milliseconds since 1 Jan 1970 to a dateTime item. |
Examples |
|
convert:dateTime-to-ms
Signatures | convert:dateTime-to-ms($dateTime as xs:dateTime) as xs:integer |
Summary | Converts the specified $dateTime to number of milliseconds since 1 Jan 1970. |
Examples |
|
Errors
Code | Description |
---|---|
BXCO0001
|
The input is an invalid XML string, or the wrong encoding has been specified. |
BXCO0002
|
The specified encoding is invalid or not supported. |
Changelog
The module was introduced with Version 7.3. Some of the functions have been adopted from the obsolete Utility Module.