XQuery Built-In Functions
AppServerBuiltins
Extension
SearchBuiltins
UpdateBuiltins
Security
 XQuery Module Functions
Security-sec
Thesaurus
Spell
 W3C XQuery Reference
W3C XQuery Functions
W3C XQuery Language

Built-In: Extension

The extension built-in functions are miscellaneous extensions to the XQuery core library, including functions for evaluating strings as XQuery expressions and functions to get information about documents in the database.

Function Summary
xdmp:access Returns whether a given action on the specified document URI would succeed.
xdmp:collection-locks Returns locks of documents in a collection.
xdmp:collection-properties Returns properties of documents in a collection.
xdmp:content-type Returns the content type of the given URI as matched in the mimetypes configuration.
xdmp:database Returns the the ID of the database specified as the argument.
xdmp:database-forests Returns a sequence of forest IDs in the specified database.
xdmp:database-name Return the name of the database with the given ID.
xdmp:databases Returns a sequence of the ids of all the databases in the system.
xdmp:describe Returns a string whose value corresponds to the description of a given item sequence.
xdmp:directory Returns the documents in a directory.
xdmp:directory-locks Returns locks of documents in a directory.
xdmp:directory-properties Returns properties of documents in a directory.
xdmp:document-forest Returns the forest ID of the forest in which the document with the specified URI is stored.
xdmp:document-get-collections Returns the collections to which a given document belongs.
xdmp:document-get-properties Returns the property values for a document's property.
xdmp:document-get-quality Returns the quality of the specified document if the document exists.
xdmp:document-locks Returns the locks for one or more documents or directories.
xdmp:document-properties Returns a sequence of properties for the specified document(s).
xdmp:email Send an email in an XQuery program.
xdmp:estimate Returns the number of fragments selected by an expression.
xdmp:eval Returns the result of evaluating a string as an XQuery.
xdmp:eval-in Returns the result of evaluating a string as an XQuery in a given database.
xdmp:forest Returns the the ID of the forest specified as the argument.
xdmp:forest-databases Returns the database ID corresponding to the database to which the specified forest belongs.
xdmp:forest-name Return the name of the forest with the given id.
xdmp:forests Returns a sequence of the ids of all the forests in the system.
xdmp:get Returns the document in the XML file specified by $path.
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:log Logs a debug message to the log file <install_dir>/Logs/ErrorLog.txt.
xdmp:node-uri Returns the document-uri property of the argument or its ancestor.
xdmp:octal-to-integer Parses an octal string, returning an integer.
xdmp:path Returns a string whose value corresponds to the path of the node.
xdmp:platform Returns the platform upon which Content Interaction Server is running ("solaris", "winnt", or "linux").
xdmp:product-edition Returns the current Mark Logic product edition.
xdmp:product-initials Returns the current Mark Logic product initials.
xdmp:product-name Returns the current Mark Logic product name.
xdmp:query-meters Returns the current value of the resource meters for this query sequence.
xdmp:query-trace Enables or disables tracing of this query.
xdmp:quote Returns the unevaluated serialized representation of the input argument as a string.
xdmp:random Returns a random unsigned integer up to 64 bits long.
xdmp:schema-database Returns the database ID of the schema database associated with the current database.
xdmp:security-database Returns the database ID of the security database associated with the current database.
xdmp:strftime Formats a dateTime value using POSIX strftime.
xdmp:unquote Parses a string as XML, returning a node.
xdmp:version Returns the current Content Interaction Server version.
Function Detail
xdmp:access(
$uri as xs:string,
$action as xs:string
)  as  xs:boolean
Summary:
Returns whether a given action on the specified document URI would succeed.
Parameters:
$uri : The document URI.
$action : The type of access: "create", "insert", "update", or "execute".
Example:
  xdmp:access(
         "http://example.com/foo.xml",
         "create")
   => true()
xdmp:collection-locks(
$uri as xs:string*
)  as  element(lock:lock)*
Summary:
Returns locks of documents in a collection.
Parameters:
$uri : The input URI.
Example:
  for $d in xdmp:collection-locks(
                     ("http://example.com/col1/",
                      "http://example.com/col2/"))
  return base-uri($d)
  => http://example.com/bar.xml 
     http://example.com/baz.xml
xdmp:collection-properties(
$uri as xs:string*
)  as  element(prop:properties)*
Summary:
Returns properties of documents in a collection.
Parameters:
$uri : The input URI.
Example:
  for $d in xdmp:collection-properties(
                   ("http://example.com/col1/",
                    "http://example.com/col2/"))
  return base-uri($d)
  => http://example.com/bar.xml http://example.com/baz.xml
xdmp:content-type(
$uri as xs:string
)  as  xs:string
Summary:
Returns the content type of the given URI as matched in the mimetypes configuration.
Parameters:
$uri : The document URI.
Example:
  xdmp:content-type("example.txt")
  => text/plain
Example:
  xdmp:content-type("example.xml")
  => text/xml
Example:
  xdmp:content-type("example.doc")
  => application/msword
xdmp:database(
[$name as xs:string]
)  as  xs:unsignedLong
Summary:
Returns the the ID of the database specified as the argument.
Parameters:
$name (optional): The name of the database.
Example:
  xdmp:database("myDB")
  => 74495681647284736476
xdmp:database-forests(
$database as xs:unsignedLong
)  as  xs:unsignedLong*
Summary:
Returns a sequence of forest IDs in the specified database.
Parameters:
$database : The ID of the database in question.
Example:
  xdmp:database-forests(xdmp:database("Documents"))
  => (8456374036761185098, 10615125154705099114)
xdmp:database-name(
$id as xs:unsignedLong
)  as  xs:string
Summary:
Return the name of the database with the given ID.
Parameters:
$id : The ID of the database in question.
Example:
xdmp:database-name(8456374036761185098)
=> "Documents"
xdmp:databases ( )  as  xs:unsignedLong*
Summary:
Returns a sequence of the ids of all the databases in the system.
Example:
  xdmp:databases()
   => (14389140626518478220,
          8456374036761185098,
	  10615125154705099114)
xdmp:describe(
$item as item()*,
[$maxLength as xs:unsignedInt]
)  as  xs:string
Summary:
Returns a string whose value corresponds to the description of a given item sequence.
Parameters:
$item : The item sequence whose description is returned.
$maxLength (optional): Represents the number of elements in the sequence to print. Default: 3
Example:
  xdmp:describe(current-date())
  => xs:date("2003-04-15-08:00")
xdmp:directory(
$uri as xs:string*,
$depth as xs:string
)  as  element()*
Summary:
Returns the documents in a directory.
Parameters:
$uri : The input URI.
$depth : "1" for immediate children, "infinity" for all.
Example:
  for $d in xdmp:directory("http://example.com/foo/","1")
  return base-uri($d)
  => http://example.com/foo/bar.xml 
     http://example.com/foo/baz.xml
xdmp:directory-locks(
$uri as xs:string*,
$depth as xs:string
)  as  element(lock:lock)*
Summary:
Returns locks of documents in a directory.
Parameters:
$uri : The input URI.
$depth : "1" for immediate children, "infinity" for all.
Example:
  for $d in xdmp:directory-locks("http://example.com/foo/","1")
  return base-uri($d)
  => http://example.com/foo/bar.xml 
     http://example.com/foo/baz.xml
xdmp:directory-properties(
$uri as xs:string,
$depth as xs:string
)  as  element(prop:properties)*
Summary:
Returns properties of documents in a directory.
Parameters:
$uri : The input URI.
$depth : "1" for immediate children, "infinity" for all children.
Example:
  xdmp:directory-properties("http://example.com/dir/","1")
  => <prop:properties 
            xmlns:prop="http://marklogic.com/xdmp/property">
         <prop:directory/>
     </prop:properties>
   

The properties document returned has one directory element, indicating that there is a single directory that is an immediate child of the specified directory.

xdmp:document-forest(
$uri as xs:string
)  as  xs:integer?
Summary:
Returns the forest ID of the forest in which the document with the specified URI is stored. Otherwise, returns the empty sequence.
Parameters:
$uri : The URI of the document.
Example:
  xdmp:document-forest("example.xml")
  => 12972338785465832200
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:document-get-properties(
$uri as xs:string,
$property as xs:QName
)  as  element()*
Summary:
Returns the property values for a document's property.
Parameters:
$uri : The document URI.
$property : The property name.
Example:
  xdmp:document-get-properties(
         "http://example.com/foo.xml",
         expanded-QName("http://examples.com/","priority"))
   => <priority xmlns="http://examples.com/">5</priority>
xdmp:document-get-quality(
$uri as xs:string
)  as  xs:integer?
Summary:
Returns the quality of the specified document if the document exists. Otherwise, returns the empty sequence.
Parameters:
$uri : The URI of the document in question.
Example:
  xdmp:document-get-quality("example.xml")
  => 10
xdmp:document-locks(
[$uri as xs:string*]
)  as  element(lock:lock)*
Summary:
Returns the locks for one or more documents or directories. With no arguments specified, returns a sequence of the locks for all documents and directories in the database.
Parameters:
$uri (optional): The document URI.
Example:
  xdmp:document-locks("example.xml")
  => <lock:lock>
          <lock:active-locks>
            <lock:active-lock>
              <lock:lock-type>write</lock:lockt-ype>
              <lock:lock-scope>exclusive</lock:lock-scope>
              <lock:depth>infinity</lock:depth>
              <lock:owner>
                http://example.com/~user
              </lock:owner>
              <lock:timeout>5000</lock:timeout>
              <lock:lock-token>
                  http://marklogic.com/xdmp/locks/e71d4fae
              </lock:lock-token>
              <lock:timestamp>5234768</lock:timestamp>
              <sec:user-id>52378234768</sec:user-id>
            </lock:active-lock>
          </lock:active-locks>
        </lock:lock>
xdmp:document-properties(
[$uri as xs:string*]
)  as  element(prop:properties)*
Summary:
Returns a sequence of properties for the specified document(s). If no documents are specified, returns the properties for all documents in the database that contain properties.
Parameters:
$uri (optional): A sequence of document URIs.
Example:
  xdmp:document-properties()
    => 
    <prop:properties 
          xmlns:prop="http://marklogic.com/xdmp/property">
    Property Node1
    </prop:properties>
    <prop:properties 
          xmlns:prop="http://marklogic.com/xdmp/property">
    Property Node2
    </prop:properties>
    <prop:properties 
          xmlns:prop="http://marklogic.com/xdmp/property">
    Property NodeN
    </prop:properties>
xdmp:email(
$message as node()
)  as   empty()
Summary:
Send an email in an XQuery program. A valid SMTP Relay must be configured in the Groups page of the Admin console 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 Content Interaction 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>Mark Logic</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>Mark Logic</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:estimate(
$expression as item()*
)  as  xs:integer
Summary:
Returns the number of fragments selected by an expression. This can be used as a fast estimate of the number of items in a sequence. Throws an exception if a fast estimate cannot be performed.
Parameters:
$expression : An expression to estimate. This must be a partially searchable path expression or a cts:search() expression.
Example:
  xdmp:estimate(input())
   => 10476
xdmp:eval(
$xquery as xs:string,
[$vars as item()*]
)  as  item()*
Summary:
Returns the result of evaluating a string as an XQuery.
Parameters:
$xquery : The XQuery string to be evaluated. If the XQuery string contains double quotes ("), surround the string with single quotes (').
$vars (optional): The external variable values for this evaluation. This must be a sequence of even length, alternating QNames and items. Each QName and item pair specify a variable name and value.
Example:
  xdmp:eval("1+1")
  => 2
Example:
let $s := 
      "define variable $x as xs:string external
       concat('hello ', $x)"
return 
    (: evaluate the query string $s using the variables 
       supplied as the second argument to xdmp:eval :)
    xdmp:eval($s, (xs:QName("x"), "world"))

=> hello world
  
xdmp:eval-in(
$xquery as xs:string,
$ID as xs:unsignedLong,
[$vars as item()*]
)  as  item()*
Summary:
Returns the result of evaluating a string as an XQuery in a given database.
Parameters:
$xquery : The XQuery string to be evaluated. If the XQuery string contains double quotes ("), surround the string with single quotes (').
$ID : The database ID, from xdmp:database("db_name"), xdmp:security-database(), or xdmp:schema-database().
$vars (optional): The external variable values for this evaluation. This must be a sequence of even length, alternating QNames and items. Each QName and item pair specify a variable name and value.
Example:
  xdmp:eval-in("1+1",2348790529)
  => 2
Example:
let $s := 
       "define variable $x as xs:string external
       concat('hello ', $x)"
return 
    (: evaluate the query string $s using the variables 
       supplied as the third argument to xdmp:eval-in :)
    xdmp:eval-in($s, 
                 xdmp:database("Documents"), 
		 (xs:QName("x"), 
		 "world"))

=> hello world
  
xdmp:forest(
$name as xs:string
)  as  xs:unsignedLong
Summary:
Returns the the ID of the forest specified as the argument.
Parameters:
$name : The name of the forest.
Example:
  xdmp:forest("myForest")
  => 15495681647217162987
xdmp:forest-databases(
$forest as xs:unsignedLong
)  as  xs:unsignedLong
Summary:
Returns the database ID corresponding to the database to which the specified forest belongs.
Parameters:
$forest : The ID of the forest in question.
Example:
  xdmp:forest-databases(xdmp:forest("Documents"))
  => 2032458498523149048
xdmp:forest-name(
$id as xs:unsignedLong
)  as  xs:string
Summary:
Return the name of the forest with the given id.
Parameters:
$id : The ID of the forest in question.
Example:
xdmp:forest-name(8456374036761185098)
=> "Documents"
xdmp:forests ( )  as  xs:unsignedLong*
Summary:
Returns a sequence of the ids of all the forests in the system.
Example:
  xdmp:forests()
   => 18263538320779601865
2760886727871312968
1551965607977434000
2714941248661564752
xdmp:get(
$path as xs:string,
[$default-namespace as xs:string],
[$options as xs:string*]
)  as  xs:node()
Summary:
Returns the document in the XML file specified by $path.
Parameters:
$path : The path to the input file. The path can be fully qualifed or relative. Relative pathnames are resolved from the directory in which Content Interaction Server is installed.
$default-namespace (optional): Default namespace for nodes in the first argument. If $default-namespace is specified and the root node of the loaded document does not explicitly specify a namespace, $default-namespace will be applied to the root node. The default value for $default-namespace is "".
$options (optional): The options for getting this document. The default value is ().

Options include:

"repair-full"
Specifies that malformed XML content be repaired. This option has no effect on binary or text documents.
"repair-none"
Specifies that malformed XML content be rejected. This option has no effect on binary or text documents.
"format-text"
Specifies to get the document as a text document, regardless of the URI specified.
"format-binary"
Specifies to get the document as a binary document, regardless of the URI specified.
"format-xml"
Specifies to get the document as an XML document, regardless of the URI specified.
"lang=en"
Specifies that the document is in english.
Usage Notes:

If no format is specified in $options, it is specified by the document content type specified by the extension of the document URI. The mimetype extensions and corresponding content types are set in the Admin console.

If neither "repair-full" nor "repair-none" is present, malformed XML content will be repaired.

Example:
  xdmp:get("foo.xml")
  => <foo/>
Example:
  xdmp:get("foo.html", "", ("repair-full", "format-xml"))
  => foo.html as an XML document that has gone through any 
        needed tag repair
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:log(
$msg as item()*,
[$level as xs:string]
)  as  empty()
Summary:

Logs a debug message to the log file <install_dir>/Logs/ErrorLog.txt.

Parameters:
$msg : Message for logging.
$level (optional): One of: emergency, alert, critcal, error, warning, notice, info, config, debug, fine, finer, or finest.
Example:
  xdmp:log("AAAA")
  => ()
xdmp:node-uri ( )  as  xs:string
Summary:
Returns the document-uri property of the argument or its ancestor.
Example:
  xdmp:node-uri(doc("http://marklogic.com/document"))
   => "http://marklogic.com/document"
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:path(
$node as node(),
[$includeDocument as xs:boolean]
)  as  xs:string