This page was generated
August  8,  2011
2:23  AM
XQuery Built-In and Modules Function Reference

Built-In: Extension - Extension Functions

The extension functions provide miscellaneous extensions to XQuery.

Function Summary
xdmp:add64 Add two 64-bit integer values, discarding overflow.
xdmp:base64-decode Converts base64-encoded string to plaintext.
xdmp:base64-encode Converts plaintext into base64-encoded string.
xdmp:castable-as Returns true if a value is castable.
xdmp:document-get-collections Returns the collections to which a given document belongs.
xdmp:element-content-type Returns the schema-defined content-type of an element ("empty", "simple", "element-only", or "mixed").
xdmp:email Send an email in an XQuery program.
xdmp:group Returns the the ID of the group specified in the parameter.
xdmp:hash32 Returns the 32-bit hash of a string.
xdmp:hash64 Returns the 64-bit hash of a string.
xdmp:hex-to-integer Parses a hexadecimal string, returning an integer.
xdmp:integer-to-hex Returns a hexadecimal representation of an integer.
xdmp:integer-to-octal Returns an octal representation of an integer.
xdmp:md5 Calculates the md5 hash of the given argument.
xdmp:mul64 Muliply two 64-bit integer values, discarding overflow.
xdmp:node-kind Returns an xs:string representing the node's kind: either "document", "element", "attribute", "text", "namespace", "processing-instruction", "binary", or "comment".
xdmp:octal-to-integer Parses an octal string, returning an integer.
xdmp:random Returns a random unsigned integer between 0 and a number up to 64 bits long.
xdmp:sleep Delays for a specific amount of time.
xdmp:strftime Formats a dateTime value using POSIX strftime.
xdmp:user-last-login Returns the last-login node for the specified user ID.
Function Detail
xdmp:add64(
$x as xs:unsignedLong,
$y as xs:unsignedLong
)  as   xs:unsignedLong
Summary:

Add two 64-bit integer values, discarding overflow.

Parameters:
$x : The first value.
$y : The second value.

Example:
  xdmp:add64(11442580934957149475,14565934789622151058)
  => 7561771650869748917

xdmp:base64-decode(
$encoded as xs:string
)  as   xs:string
Summary:

Converts base64-encoded string to plaintext.

Parameters:
$encoded : Encoded text to be decoded.

Example:
xdmp:base64-decode(
     "c2xpbmdzIGFuZCBhcnJvd3Mgb2Ygb3V0cmFnZW91cyBmb3J0dW5l")
=> slings and arrows of outrageous fortune

xdmp:base64-encode(
$plaintext as xs:string
)  as   xs:string
Summary:

Converts plaintext into base64-encoded string.

Parameters:
$plaintext : Plaintext to be encoded.

Example:
  xdmp:base64-encode("slings and arrows of outrageous fortune")
   => c2xpbmdzIGFuZCBhcnJvd3Mgb2Ygb3V0cmFnZW91cyBmb3J0dW5l

xdmp:castable-as(
$namespace-uri as xs:string,
$local-name as xs:string,
$item as item()
)  as   xs:boolean
Summary:

Returns true if a value is castable. This is similar to the "castable as" XQuery predicate, except that the type is determined at runtime.

Parameters:
$namespace-uri : The namespace URI of the type.
$local-name : The local-name of the type.
$item : The item to be cast.

Example:
  xdmp:castable-as(
    "http://www.w3.org/2001/XMLSchema",
    "integer",
    "12")
    => true()

xdmp:document-get-collections(
$uri as xs:string
)  as   xs:string*
Summary:

Returns the collections to which a given document belongs.

Parameters:
$uri : The document URI.

Example:
  xdmp:document-get-collections("chapter5.xml")
  =>("http://marklogic.com/all-books", 
        "http://marklogic.com/xml-books")

xdmp:element-content-type(
$element as element()
)  as   xs:string
Summary:

Returns the schema-defined content-type of an element ("empty", "simple", "element-only", or "mixed").

Parameters:
$element : An element node.

Example:
  xdmp:element-content-type()
  => "element-only"

xdmp:email(
$message as node()
)  as   empty-sequence()
Summary:

Send an email in an XQuery program. A valid SMTP Relay must be configured in the Groups page of the Admin Interface for the email to be sent. The format of the email message must be an XML file that complies with the schema files listed below.

Parameters:
$message : An XML representation of an email message to send. The message must comply with the XML schemas defined in the following schema files:
  • install_dir/Config/email-xml.xsd
  • install_dir/Config/rfc822.xsd
where install_dir is the directory in which MarkLogic Server is installed.

Required Privilege:

http://marklogic.com/xdmp/privileges/xdmp-email

Example:
This example demonstrates sending a message with 
HTML content.
   
xdmp:email(
<em:Message 
 xmlns:em="URN:ietf:params:email-xml:" 
 xmlns:rf="URN:ietf:params:rfc822:">
  <rf:subject>Sample HTML Email</rf:subject>
  <rf:from>
    <em:Address>
      <em:name>MarkLogic</em:name>
      <em:adrs>marklogic@yourdomain</em:adrs>
    </em:Address>
  </rf:from>
  <rf:to>
    <em:Address>
      <em:name>System Administrator</em:name>
      <em:adrs>admin@yourdomain</em:adrs>
    </em:Address>
  </rf:to>
  <em:content>
    <html xmlns="http://www.w3.org/1999/xhtml"> 
      <head>
        <title>Test HTML message</title>
      </head>
      <body>
        <h1>Test HTML message</h1>
        <p>Here is a simple paragraph</p>
      </body> 
    </html>
  </em:content>
</em:Message>)

Example:
This example demonstrate sending a message with 
plain text content. 

xdmp:email(
<em:Message 
 xmlns:em="URN:ietf:params:email-xml:" 
 xmlns:rf="URN:ietf:params:rfc822:">
  <rf:subject>Sample Plain Text Email</rf:subject>
  <rf:from>
    <em:Address>
      <em:name>MarkLogic</em:name>
      <em:adrs>marklogic@yourdomain</em:adrs>
    </em:Address>
  </rf:from>
  <rf:to>
    <em:Address>
      <em:name>System Administrator</em:name>
      <em:adrs>admin@yourdomain</em:adrs>
    </em:Address>
  </rf:to>
  <em:content xml:space="preserve">
This is a sample email with a plain text body.
</em:content>
</em:Message>)


xdmp:group(
[$name as xs:string]
)  as   xs:unsignedLong
Summary:

Returns the the ID of the group specified in the parameter. Returns the ID of the current group if no parameter is specified.

Parameters:
$name (optional): The name of the group. The default value is the name of the group the current host belongs to.

Example:
  xdmp:group("Default")
  => 134722342511344334243

xdmp:hash32(
$string as xs:string
)  as   xs:unsignedInt
Summary:

Returns the 32-bit hash of a string.

Parameters:
$string : The string to be hashed.

Example:
  xdmp:hash32("/a/b[1]/c")
  => 152930691

xdmp:hash64(
$string as xs:string
)  as   xs:unsignedLong
Summary:

Returns the 64-bit hash of a string.

Parameters:
$string : The string to be hashed.

Example:
  xdmp:hash64("/a/b[1]/c")
  => 5082244643751628547

xdmp:hex-to-integer(
$hex as xs:string
)  as   xs:integer
Summary:

Parses a hexadecimal string, returning an integer.

Parameters:
$hex : The hexadecimal string.

Example:
  xdmp:hex-to-integer("1234567890abcdef")
   => 1311768467294899695

xdmp:integer-to-hex(
$val as xs:integer
)  as   xs:string
Summary:

Returns a hexadecimal representation of an integer.

Parameters:
$val : The integer value.

Example:
  xdmp:integer-to-hex(1234567890)
   => "499602d2"

xdmp:integer-to-octal(
$val as xs:integer
)  as   xs:string
Summary:

Returns an octal representation of an integer.

Parameters:
$val : The integer value.

Example:
  xdmp:integer-to-octal(1234567890)
   => "11145401322"

xdmp:md5(
$encoded as xs:string
)  as   xs:string
Summary:

Calculates the md5 hash of the given argument.

Parameters:
$encoded : String to be hashed.

Example:
  xdmp:md5("foo")
  => "acbd18db4cc2f85cedef654fccc4a4d8"
 

xdmp:mul64(
$x as xs:unsignedLong,
$y as xs:unsignedLong
)  as   xs:unsignedLong
Summary:

Muliply two 64-bit integer values, discarding overflow.

Parameters:
$x : The first value.
$y : The second value.

Example:
  xdmp:mul64(15107650474313474666,13290239292956375463)
  => 1404109880107289894

xdmp:node-kind(
$node as node()?
)  as   xs:string
Summary:

Returns an xs:string representing the node's kind: either "document", "element", "attribute", "text", "namespace", "processing-instruction", "binary", or "comment".

The fn:node-kind builtin was dropped from the final XQuery 1.0 spec. This is the equivalent function in the xdmp: namespace carried over for MarkLogic 1.0 dialects.


Parameters:
$node : The node whose kind is to be returned.

Example:
let $x := <hello><goodbye>1</goodbye></hello>
return
xdmp:node-kind($x/node())

=> element

xdmp:octal-to-integer(
$octal as xs:string
)  as   xs:integer
Summary:

Parses an octal string, returning an integer.

Parameters:
$octal : The octal string.

Example:
  xdmp:octal-to-integer("12345670")
   => 2739128

xdmp:random(
[$max as xs:unsignedLong]
)  as   xs:unsignedLong
Summary:

Returns a random unsigned integer between 0 and a number up to 64 bits long.

Parameters:
$max (optional): The optional maximum value (inclusive).

Example:
  xdmp:random(100)
  => 47

xdmp:sleep(
$msec as xs:unsignedInt
)  as   empty-sequence()
Summary:

Delays for a specific amount of time.

Parameters:
$msec : The amount of time to sleep, in milliseconds.

Example:
  xdmp:sleep(1000)
   => ()

xdmp:strftime(
$format as xs:string,
$value as xs:dateTime
)  as   xs:string
Summary:

Formats a dateTime value using POSIX strftime.

Parameters:
$format : The strftime format string.
$value : The dateTime value.

Usage Notes:

The supported format strings differ for different platforms. For the supported format strings for Windows, see the following link:

http://msdn2.microsoft.com/en-us/library/fe06s4ak(VS.80).aspx

For the supported format strings for Solaris, see the following link:

http://docs.sun.com/app/docs/doc/817-5438/6mkt5pcec?a=view

For the supported format strings for Linux, see the following link:

http://linux.about.com/library/cmd/blcmdl3_strftime.htm


Example:
  xdmp:strftime("%a, %d %b %Y %H:%M:%S",current-dateTime())
   => Tue, 08 Apr 2003 17:21:37

xdmp:user-last-login(
$user as xs:unsignedLong
)  as   element(last-login)?
Summary:

Returns the last-login node for the specified user ID. If no user ID is specified, then the current user is assumed. If no last-login database is specified in the App Server configuration, then the empty sequence is returned.

Parameters:
$user : A user ID.

Example:
  xdmp:user-last-login(xdmp:user("sylvester"))
  => 
  <last-login xmlns="http://marklogic.com/xdmp/last-login">
    <user-id>1134406269933351074</user-id>
    <last-successful-login>2008-03-19T15:41:08</last-successful-login>
    <last-unsuccessful-login>2008-03-19T15:40:45</last-unsuccessful-login>
    <number-unsuccessful-logins>0</number-unsuccessful-logins>
    <display-last-login>true</display-last-login>
  </last-login>