Output Module

From BaseX Documentation
Revision as of 14:14, 10 October 2011 by Michael (talk | contribs) (Text replace - "<font color='orangered'>Version 7.0</font>" to "{{Version|7.0}}")
Jump to navigation Jump to search

This module contains auxiliary XQuery Functions, which can be used to perform data conversions and test and profile code snippets. All functions are preceded by the util: prefix, which is linked to the http://www.basex.org/util namespace.

util:eval

Signatures util:eval($expr as xs:string) as item()*
Summary Evaluates $expr as XQuery expression at runtime and returns the resulting items.
Examples
  • util:eval("1+3") returns 4.

util:run

Signatures util:run($input as xs:string) as item()*
Summary Opens $input as file, evaluates it as XQuery expression at runtime, and returns the resulting items.

util:format

Signatures util:format($format as xs:string, $item1 as item(), ...) as xs:string
Summary Returns a formatted string. $item1 and all following items are applied to the $format string, according to Java’s printf syntax.
Examples
  • util:format("%b", true()) returns true.
  • util:format("%06d", 256) returns 000256.
  • util:format("%e", 1234.5678) returns 1.234568e+03.

util:mb

Signatures util:mb($expr as item()) as xs:double
util:mb($expr as item(), $cache as xs:boolean) as xs:double
Summary Measures the amount of memory that is needed to evaluate $expr.
The returned xs:double value represents the amount of memory in megabytes.
If the value of $cache is true(), the result will be cached.
Examples
  • util:mb("1 to 100000") might return 0.
  • util:mb("1 to 100000", true()) might return 26.678.

util:ms

Signatures util:ms($expr as item()) as xs:double
util:ms($expr as item(), $cache as xs:boolean) as xs:double
Summary Measures the time needed to evaluate $expr.
The returned xs:double value represents the needed time in milliseconds.
If the value of $cache is true(), the result will be cached.
Examples
  • util:ms("1 to 100000") might return 25.69.
  • util:ms("1 to 100000", true()) might return 208.12.

util:integer-to-base

Signatures util: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
  • util:integer-to-base(-1, 16) returns the hexadecimal string 'ffffffffffffffff'.
  • util:integer-to-base(22, 5) returns '42'.

util:integer-from-base

Signatures util: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
  • util:integer-from-base('ffffffffffffffff', 16) returns -1.
  • util:integer-from-base('CAFEBABE', 16) returns 3405691582.
  • util:integer-from-base('42', 5) returns 22.
  • util:integer-from-base(util:integer-to-base(123, 7), 7) returns 123.

util:md5

Signatures util:md5($str as xs:string) as xs:hexBinary
Summary Calculates the MD5 hash of the given string $str.
Examples
  • util:md5("") returns 'D41D8CD98F00B204E9800998ECF8427E'.
  • util:md5('BaseX') returns '0D65185C9E296311C0A2200179E479A2'.

util:sha1

Signatures util:sha1($str as xs:string) as xs:hexBinary
Summary Calculates the SHA1 hash of the given string $str.
Examples
  • util:sha1("") returns 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709'.
  • util:sha1("BaseX") returns '3AD5958F0F27D5AFFDCA2957560F121D0597A4ED'.

util:crc32

Signatures util:crc32($str as xs:string) as xs:hexBinary
Summary Calculates the CRC32 check sum of the given string $str.
Examples
  • util:crc32("") returns '00000000'.
  • util:crc32("BaseX") returns '4C06FC7F'.

util:to-bytes

Signatures util:to-bytes($bin as xs:base64Binary) as xs:byte*
Summary Extracts the bytes from the given binary data $bin.
Examples
  • util:to-bytes(xs:base64Binary('QmFzZVggaXMgY29vbA==')) returns the sequence (66, 97, 115, 101, 88, 32, 105, 115, 32, 99, 111, 111, 108).
  • util:to-bytes(xs:base64Binary(xs:hexBinary("4261736558"))) returns the sequence (66 97 115 101 88).

util:uuid

Signatures util:uuid() as xs:string.
Summary Creates a random universally unique identifier (UUID), represented as 128-bit value. Introduced with Version 7.0
Examples
  • util:uuid() ne util:uuid() will (most probably) return the boolean value true.