This page was generated
July 7, 2010
4:02 PM
XQuery Built-In and Modules Function Reference

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:add64 Add two 64-bit integer values, discarding overflow.
xdmp:architecture Returns the hardware architecture upon which MarkLogic Server is running.
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:collation-canonical-uri Returns the canonical URI for the given URI, if it represents a valid collation.
xdmp:collection-locks Returns locks of documents in a collection.
xdmp:collection-properties Returns a sequence of properties documents, one for each document in the specified collection(s) that has a corresponding properties document.
xdmp:database Returns the the ID of the database named in the the parameter.
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 representing the description of a given item sequence.
xdmp:diacritic-less Returns the specified string, converting all of the characters with diacritics to characters without diacritics.
xdmp:directory Returns the documents in a directory.
xdmp:directory-locks Returns locks of documents in a directory.
xdmp:directory-properties Returns a sequence of properties documents, one for each document in the specified directory that has a corresponding properties document.
xdmp:document-forest Returns the forest ID of the forest in which a document (or a lock or a property) with the specified URI is stored.
xdmp:document-get Returns the document in the file specified by $location.
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 documents, one for each of the specified documents that has a corresponding properties document.
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 module.
xdmp:eval-in [DEPRECATED: use xdmp:eval with the database option instead] Returns the result of evaluating a string as an XQuery module in a given database.
xdmp:exists Returns true if any fragment is selected by an expression, false if no fragments are selected.
xdmp:forest Returns the the ID of the forest specified as the parameter.
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 [DEPRECATED: use xdmp:document-get instead] Returns the document in the XML file specified by $path.
xdmp:group Returns the the ID of the group specified in the parameter.
xdmp:group-hosts Returns the IDs of all hosts belonging to the group with the given ID.
xdmp:group-name Returns the the name of the group with the given ID.
xdmp:group-servers Returns the the IDs of all App Servers belonging to the group with the given ID.
xdmp:groups Returns a sequence of the IDs of all the groups in the system.
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:host Returns the the ID of the host named in the parameter.
xdmp:host-name Returns the the name of the host ID specified as the parameter.
xdmp:hosts Returns a sequence of the IDs of all the hosts in the system.
xdmp:http-delete Sends an http DELETE request to the http server specified in the URI to delete the specified resource.
xdmp:http-get Sends the http GET method to the specified URI.
xdmp:http-head Sends the http HEAD method to the specified URI.
xdmp:http-options Sends the http OPTIONS method to the specified URI.
xdmp:http-post Sends the http POST request to the server.
xdmp:http-put Sends an HTTP PUT request to an HTTP server.
xdmp:integer-to-hex Returns a hexadecimal representation of an integer.
xdmp:integer-to-octal Returns an octal representation of an integer.
xdmp:invoke Returns the result of evaluating a module at the given path.
xdmp:invoke-in [DEPRECATED: use xdmp:invoke with the database option instead] Returns the result of evaluating a module at the given path.
xdmp:log Logs a debug message to the log file <install_dir>/Logs/ErrorLog.txt.
xdmp:log-level Retrieves the current server log level.
xdmp:md5 Calculates the md5 hash of the given argument.
xdmp:modules-database Returns the database ID of the modules database.
xdmp:modules-root Returns the current root path for modules.
xdmp:mul64 Muliply two 64-bit integer values, discarding overflow.
xdmp:node-database Returns the database id where the parameter is stored.
xdmp:node-kind Returns an xs:string representing the node's kind: either "document", "element", "attribute", "text", "namespace", "processing-instruction", "binary", or "comment".
xdmp:node-uri Returns the document-uri property of the parameter 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 operating-system platform upon which MarkLogic Server is running ("solaris", "winnt", or "linux").
xdmp:product-edition Returns the current Mark Logic product edition.
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 parameter as a string.
xdmp:random Returns a random unsigned integer between 0 and a number up to 64 bits long.
xdmp:request Returns the unique key of the current request.
xdmp:request-timestamp Returns the system timestamp for this request if the request is a query statement.
xdmp:rethrow Rethrow the currently caught error.
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:server Returns the the ID(s) of the App Server specified in the parameter.
xdmp:server-name Return the name of the App Server with the given ID.
xdmp:servers Returns a sequence of the IDs of all the App Servers in the system.
xdmp:set Set the value of a variable to the specified expression.
xdmp:sleep Delays for a specific amount of time.
xdmp:spawn Place the specified module on the task queue for evaluation.
xdmp:spawn-in [DEPRECATED: use xdmp:spawn with the database option instead] Place the specified module on the task queue for evaluation.
xdmp:strftime Formats a dateTime value using POSIX strftime.
xdmp:subbinary Returns a binary node made up of a subset of the given binary node.
xdmp:trace Signal a trace event.
xdmp:triggers-database Returns the database ID of the triggers database associated with the current database.
xdmp:unpath Evaluate a string as an XPath and return the corresponding node(s).
xdmp:unquote Parses a string as XML, returning one or more document nodes.
xdmp:uri-content-type Returns the content type of the given URI as matched in the mimetypes configuration.
xdmp:uri-format Returns the format of the given URI as matched in the mimetypes configuration.
xdmp:user-last-login Returns the last-login node for the specified user ID.
xdmp:value Evaluate an expression in the context of the current evaluating statement.
xdmp:version Returns the current MarkLogic Server version.
xdmp:with-namespaces Evaluates the expression in the context of a specific set of namespace bindings.
xdmp:xquery-version Returns the XQuery language version of the calling module.
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: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:architecture( ) as xs:string
Summary:

Returns the hardware architecture upon which MarkLogic Server is running. If xdmp:platform() returns "linux", it will return "x86_64" or "i686. If xdmp:platform() returns "solaris", it will return "amd64" or "sparcv9". If xdmp:platform() returns "winnt", it will return "amd64" or "i686".

Example:
  xdmp:architecture()
   => "amd64"

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:collation-canonical-uri(
$collation-uri as xs:string
)  as  xs:string
Summary:

Returns the canonical URI for the given URI, if it represents a valid collation. A canonical URI is the unique string MarkLogic Server uses to identify a given collation. The canonical URI string places any attributes that occur in the URI in a predefined order, and it removes any attributes that are redundant due to locale defaults.

Parameters:
$collation-uri : A collation URI.

Usage Notes:

If the specified collation URI is not a valid URI, an exception is thrown.

Example:
xdmp:collation-canonical-uri("http://marklogic.com/collation/en/S3") 
=> http://marklogic.com/collation/en

xdmp:collection-locks(
[$uri as xs:string*]
)  as  document-node()*
Summary:

Returns locks of documents in a collection.

Parameters:
$uri (optional): The input URI.

Example:
  for $d in xdmp:collection-locks(
                     ("http://example.com/col1/",
                      "http://example.com/col2/"))
  return xdmp:node-uri($d)
  => http://example.com/bar.xml 
     http://example.com/baz.xml

xdmp:collection-properties(
[$uri as xs:string*]
)  as  document-node()*
Summary:

Returns a sequence of properties documents, one for each document in the specified collection(s) that has a corresponding properties document.

Parameters:
$uri (optional): The URI(s) of the collection(s).

Example:
  xquery version "0.9-ml"
  declare namespace cpf="http://marklogic.com/cpf"

  for $d in xdmp:collection-properties(
                   ("http://example.com/col1/",
                    "http://example.com/col2/"))
  where $d/property::cpf:error
  return xdmp:node-uri($d)

  => A list of document URIs of documents that have a 
        cpf:error property in their corresponding properties 
	documents.  For example:

      http://example.com/bar.xml http://example.com/baz.xml

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

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

Parameters:
$name (optional): The name of the database. The default value is the name of the current 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 : A database ID.

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 : A database ID.

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()*,
[$maxSequenceLength as xs:unsignedInt?],
[$maxItemLength as xs:unsignedInt*]
)  as  xs:string
Summary:

Returns a string representing the description of a given item sequence. If you take the output of the xdmp:describe function and evaluate it as an XQuery program, it returns the item(s) input to the function.

Parameters:
$item : The item sequence whose description is returned.
$maxSequenceLength (optional): Represents the maximum number of items per sequence to print. The default is 3. () means no maximum.
$maxItemLength (optional): Represents the maximum number of characters per item to print. The default is 64. The minimum is 8. () means no limit.

Usage Notes:

If you specify an item that is in a database, xdmp:describe returns the path to the item (or to the items if you specify multiple items). If the item or items are constructed in XQuery, then it prints out the item, truncating the characters in each item according to the maxItemLength parameter.


Example:
  xdmp:describe(current-date())

  => xs:date("2007-01-15-08:00")
Example:
  let $x := <mynode>Some text here.</mynode>
  return
  xdmp:describe($x)

  => <mynode>Some text here.</mynode>
Example:
  (:  assume mydoc.xml is an XML document with
      the following content:
      <mynode>Some text here.</mynode> :)
  xdmp:describe(doc("mydoc.xml")/mynode)

  => doc("mydoc.xml")/mynode

xdmp:diacritic-less(
$string as xs:string
)  as  xs:string
Summary:

Returns the specified string, converting all of the characters with diacritics to characters without diacritics.

Parameters:
$string : The string to convert.

Example:
xdmp:diacritic-less("José")
=> Jose 

xdmp:directory(
$uri as xs:string*,
[$depth as xs:string]
)  as  document-node()*
Summary:

Returns the documents in a directory.

Parameters:
$uri : The URI of the directory. Typically, directory URIs end with a forward slash (/).
$depth (optional): "1" for immediate children, "infinity" for all. If not supplied, depth is "1".

Example:
  for $d in xdmp:directory("http://example.com/foo/","1")
  return xdmp:node-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  document-node()*
Summary:

Returns locks of documents in a directory.

Parameters:
$uri : The URI of the directory. Typically, directory URIs end with a forward slash (/).
$depth (optional): "1" for immediate children, "infinity" for all. If not supplied, depth is "1".

Example:
  for $d in xdmp:directory-locks("http://example.com/foo/","1")
  return xdmp:node-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  document-node()*
Summary:

Returns a sequence of properties documents, one for each document in the specified directory that has a corresponding properties document.

Parameters:
$uri : The URI of the directory. Typically, directory URIs end with a forward slash (/).
$depth (optional): "1" for immediate children, "infinity" for all children. If not supplied, depth is "1".

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,
[$forest-ids as xs:unsignedLong*]
)  as  xs:integer?
Summary:

Returns the forest ID of the forest in which a document (or a lock or a property) with the specified URI is stored. Otherwise, returns the empty sequence.

Parameters:
$uri : The URI of the document, lock, or property.
$forest-ids (optional): Restricts the ID(s) of the forest(s) in which this function may return.

Example:
  xdmp:document-forest("example.xml")
  => 12972338785465832200

xdmp:document-get(
$location as xs:string,
[$options as node()]
)  as  node()
Summary:

Returns the document in the file specified by $location.

Parameters:
$location : The location of the input document. If the scheme of the location is HTTP (that is, if the string starts with "http://"), then the document is requested over HTTP. Otherwise, the document is fetched from the local filesystem. On the filesystem, the path can be fully qualifed or relative. Relative pathnames are resolved from the directory in which MarkLogic Server is installed.
$options (optional): The options node for getting this document. The default value is (). The node for the xdmp:document-get options must be in the xdmp:document-get namespace. This parameter can also include option elements in the xdmp:http namespace for the HTTP parameters.

The xdmp:document-get options include:

<default-namespace>

The namespace to use if there is no namespace at the root node of the document. The default value is "".

<repair>

A value of full specifies that malformed XML content be repaired. A value of none specifies that malformed XML content is rejected. If no repair option is explicitly specified, the default is implicitly specified by the XQuery version of the caller. In XQuery 1.0 and 1.0-ml the default is none. In XQuery 0.9-ml the default is full. This option has no effect on binary or text documents.

<format>

A value of text specifies to get the document as a text document, regardless of the URI specified. A value of binary specifies to get the document as a binary document, regardless of the URI specified. A value of xml specifies to get the document as an XML document, regardless of the URI specified.

<default-language>

The language to specify in an xml:lang attribute on the root element node if the root element node does not already have an xml:lang attribute. If default-language is not specified, then nothing is added to the root element node.

<encoding>

Specifies the encoding to use when reading the document into MarkLogic Server. Supported values include UTF-8, ISO-8859-1, as well as many other popular encodings. See the Developer's Guide for a list of character set encodings by language. All encodings will be translated into UTF-8 from the specified encoding. The string specifed for the encoding option will be matched to an encoding name according to the Unicode Charset Alias Matching rules (http://www.unicode.org/reports/tr22/#Charset_Alias_Matching). If no encoding option is specified, the encoding defaults to the encoding specified in the http header (if using with one of the http functions, for example, xdmp:http-get), otherwise it defaults to UTF-8.

Required Privilege:

http://marklogic.com/xdmp/privileges/xdmp-document-get

Usage Notes:

If no format is specified in $options, and the document is from an HTTP server, the format is specified by the document content type from the HTTP response. If no format is specified in $options, and the document is from the filesystem, the format is specified by the document content type from the filename extension. The mimetype extensions and corresponding content types are set in the Admin Interface.

If no repair option is specified, the default is specified by the XQuery version of the caller. In XQuery version 1.0 and 1.0-ml the default is <repair>none</repair>. In XQuery version 0.9-ml the default is <repair>full</repair>.

When the document is from an HTTP server, xdmp:document-get will always return the response from the HTTP server, even if it is an error response such as 404 or 500. If you want to be able to examine the response header in your application, use the xdmp:http-get instead, which returns both the response header and the response.


Example:
  xdmp:document-get("myDocument.xml")
  => the xml contained in myDocument.xml, 
        for example, <myDocument/>
Example:
  xdmp:document-get("myDocument.html", 
       <options xmlns="xdmp:document-get">
           <repair>full</repair>
       </options>)
  => myDocument.html as an XML document that has gone 
     through any needed tag repair
Example:
  xdmp:document-get("http://myCompany.com/file.xml", 
       <options xmlns="xdmp:document-get"
                xmlns:http="xdmp:http">
           <format>xml</format>
           <http:authentication>
	      <http:username>user</http:username>
	      <http:password>pass</http:password>
	   </http:authentication>
       </options>)
  => gets an XML document named file.xml, sending the 
     authentication credentials user/pass to the 
     http://myCompany.com server
  

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. This is the QName of the top-level property element in the specified properties document.

Example:
  xdmp:document-get-properties(
         "http://example.com/foo.xml",
         fn: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  document-node()*
Summary:

Returns the locks for one or more documents or directories. Returns the locks for all documents and directories in the database if no parameter is given.

Parameters:
$uri (optional): A 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  document-node()*
Summary:

Returns a sequence of properties documents, one for each of the specified documents that has a corresponding properties document. If no documents are specified, returns a sequence of properties documents for all documents in the database that have a corresponding properties document.

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-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>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()*,
[$maximum as xs:double?]
)  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.

Parameters:
$expression : The expression to estimate. This must be a partially searchable XPath expression or a cts:search() expression.
$maximum (optional): The maximum value to return. Stop selecting fragments if this number is reached.

Usage Notes:

Queries that use xdmp:estimate require that the XPath expression searched is partially searchable. A partially searchable XPath expression is one whose first step is searchable. You can use xdmp:query-trace() to determine if a step is searchable. If there are no entries in the xdmp:query-trace() output indicating that the first step is unsearchable, then the expression is partially searchable and you can perform an xdmp:estimate operation on it.

Example:
  xdmp:estimate(collection())
   => 10476

xdmp:eval(
$xquery as xs:string,
[$vars as item()*],
[$options as node()]
)  as  item()*
Summary:

Returns the result of evaluating a string as an XQuery module.

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.
$options (optional): The options node. The default value is (). The node for the xdmp:eval options must be in the xdmp:eval namespace. The following is a sample options node:
    <options xmlns="xdmp:eval">
      <isolation>different-transaction</isolation>
      <prevent-deadlocks>true</prevent-deadlocks>
    </options> 

The xdmp:eval options include:

<database>

The database ID, from xdmp:database("db_name"), xdmp:security-database(), or xdmp:schema-database(). To specify a database other than the context database, the http://marklogic.com/xdmp/privileges/xdmp-eval-in privilege is required.

<modules>

The modules database ID for processing module imports. Specifying no <modules> element in the options node specifies the current modules database. Specifying 0 specifies using the file system to process module imports. You must have the http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change (for xdmp:eval), http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change (for xdmp:invoke), or the http://marklogic.com/xdmp/privileges/xdmp-spawn-modules-change (for xdmp:spawn) privilege to change either the modules database to another database or to change the root to another path. You must have the http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file (for xdmp:eval), http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change-file (for xdmp:invoke), or the http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file (for xdmp:spawn) privilege to change the modules database to the file system or to change a root on the filesystem.

<root>

The root path for modules. Specifying no <root> element in the options node specifies the current root. You need the same privileges to modify the root as you need to change the module option.

<timestamp>

The system timestamp to use for this evaluation. Specifying no <timestamp> element in the options node specifies the most recent timestamp. You may only specify a timestamp for a query statement, not for an update statement. The timestamp is a number that is incremented by 1 each time any configuration or content change is made to the system. Specifying a timestamp of 0 uses the current system timestamp (the value returned by xdmp:request-timestamp()). Specifying a timestamp requires the xdmp:timestamp execute privilege.

<isolation>

(Only valid with xdmp:eval or xdmp:invoke; does not apply to xdmp:spawn.) Either same-statement or different-transaction. When set to same-statement, the statement is evaluated in the same transaction as the one from which it is called, and subsequent expressions in the calling statement will not see any updates performed in the eval/invoke/spawn. You can only use same-statement isolation with update statements; query statements with same-statement isolation will throw an exception. When set to different-transaction, the statement is evaluated in a separate transaction from the one in which it is called, making those updates available to subsequent expressions in the calling statement (assuming the calling statement is an update statement; if the calling statement is not an update, then subsequent expressions will see the version of the database at the system timestamp when the calling statement begins its evaluation). When using different-transaction in an update statement that calls another update statement, do not update the same document as the calling statement is updating; doing so can cause a deadlock. You cannot evaluate a statement in a different database with the isolation option set to same-statement. The default value for the isolation option is different-transaction. For more details, see the "Understanding Transactions in MarkLogic Server" chapter of the Developer's Guide.

<prevent-deadlocks>

(Only valid with xdmp:eval or xdmp:invoke; does not apply to xdmp:spawn.) Specify true for the server to disallow update requests from an update transaction. Only has an effect when the isolation option is set to different-transaction as there is no possibility of a deadlock if the isolation option is set to same-statement. When set to true in an update request calling another update request, MarkLogic Server throws the XDMP-PREVENTDEADLOCKS exception. Setting this option to true prevents the possibility of deadlocks occurring when running eval/invoke of an update transaction from another update transaction. The default value for the prevent-deadlocks option is false.

<default-xquery-version>

The default XQuery language version to use for the query, if the query does not contain an explicit version declaration. If this option is not provided, the defaults are:
  • xdmp:eval: The XQuery language version of the module that called eval. This version may vary module-by-module if a query consists of modules written in multiple language versions. It may also vary from run to run if the app-server default is changed.
  • xdmp:invoke: The default XQuery version for the app server that the invocation occurs on. Note that this may be different than the XQuery version of the module that calls xdmp:invoke.
  • xdmp:spawn: The XQuery version default set on the app server that called xdmp:spawn. The Task Server has no default XQuery version, the version to use is passed as a part of the task request.
Allowable values for this option are "0.9-ml", "1.0-ml", "1.0" and the special value "app-server". The first three are XQuery language versions. The last indicates that the default XQuery language version set on this app-server should be used. This is useful if code written in an older XQuery version needs to call xdmp:eval on strings that may have been passed as parameters, but should be interpreted in the app-server's default language version. A module may discover its own XQuery language version with xdmp:xquery-version.

<time-limit>

Override the default time limit with this time limit, in seconds, for this evaluation. You can set the value up to the maximum-time-limit value for the App Server in which the request is evaluated or to a lower value than the default time limit. This option only applies to xdmp:spawn, not to xdmp:invoke or xdmp:eval.

<user-id>

Specifies the user ID for the user to run the request being evaluated (the request specified in the $xquery parameter). If no user-id is specified, then the request is run as the current user. You need to have the xdmp:login (http://marklogic.com/xdmp/privileges/xdmp-login) privilege to use the user-id option. Be aware that this is a very privileged operation, as it allows a user with this privilege to evaluate requests as any other user. For an example, see the fourth example below.

Required Privilege:

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

You must have the http://marklogic.com/xdmp/privileges/xdmp-eval-in privilege to specify the <database> option with a database other than the context database.

You must have the http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change (for xdmp:eval), http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change (for xdmp:invoke), or the http://marklogic.com/xdmp/privileges/xdmp-spawn-modules-change (for xdmp:spawn) privilege to change either the modules database to another database or to change the root to another path. You must have the http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file (for xdmp:eval), http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change-file (for xdmp:invoke), or the http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file (for xdmp:spawn) privilege to change the modules database to the file system or to change a root on the filesystem.

You must have the http://marklogic.com/xdmp/privileges/xdmp-login privilege to use the user-login option.


Example:
  xdmp:eval("1+1")
  => 2
Example:
xquery version "1.0-ml";
declare namespace my='http://mycompany.com/test'; 

let $s := 
      "xquery version '1.0-ml';
       declare namespace my='http://mycompany.com/test'; 
       declare variable $my:x as xs:string external;
       concat('hello ', $my:x)"
return 
    (: evaluate the query string $s using the variables 
       supplied as the second parameter to xdmp:eval :)
    xdmp:eval($s, (xs:QName("my:x"), "world"))

=> hello world
  
Example:
  xdmp:eval("doc('/docs/mydoc.xml')",  (),
		  <options xmlns="xdmp:eval">
		    <database>{xdmp:database("otherdb")}</database>
		  </options>)
  => The '/docs/mydoc.xml' document from the
     otherdb database.
Example:
xdmp:eval('xdmp:get-current-user()', (), 
 <options xmlns="xdmp:eval">
  <user-id>{xdmp:user("someuser")}</user-id>
 </options>)
(:
  returns "someuser", assuming "someuser" exists in the
  security database and the user running the eval request has the 
  xdmp:login privilege.
:)

xdmp:eval-in(
$xquery as xs:string,
$ID as xs:unsignedLong,
[$vars as item()*],
[$modules as xs:unsignedLong?],
[$root as xs:string?]
)  as  item()*
Summary:

[DEPRECATED: use xdmp:eval with the database option instead] Returns the result of evaluating a string as an XQuery module 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.
$modules (optional): The modules database for processing module imports. The empty sequence specifies the current modules database.
$root (optional): The root path for modules. The empty sequence specifies the current root.

Example:
  xdmp:eval-in("1+1",2348790529)
  => 2
Example:
xquery version "0.9-ml"
declare namespace my='http://mycompany.com/test' 

let $s := 
      "xquery version '0.9-ml'
       declare namespace my='http://mycompany.com/test' 
       define variable $my:x as xs:string external
       concat('hello ', $my:x)"
return 
    (: evaluate the query string $s using the variables 
       supplied as the second parameter to xdmp:eval :)
    xdmp:eval-in($s, 
                 xdmp:database("Documents"), 
		 (xs:QName("my:x"), 
		 "world"))

=> hello world
  

xdmp:exists(
$expression as item()*
)  as  xs:integer
Summary:

Returns true if any fragment is selected by an expression, false if no fragments are selected. This can be used as a fast existence check.

Parameters:
$expression : The expression to check. This must be a partially searchable XPath expression or a cts:search() expression.

Usage Notes:

Queries that use xdmp:exists require that the XPath expression searched is partially searchable. A partially searchable XPath expression is one whose first step is searchable. You can use xdmp:query-trace() to determine if a step is searchable. If there are no entries in the xdmp:query-trace() output indicating that the first step is unsearchable, then the expression is partially searchable and you can perform an xdmp:exists operation on it.

Calling xdmp:exists on an expression is the same as calling xdmp:estimate on the expression with a maximum of 1. For example, the following are equivalent:

     xdmp:exists(cts:search(collection(), "foo"))
     
       is equivalent to:
     
     xs:boolean(xdmp:estimate(cts:search(collection(), "foo"), 1)) 

Example:
  xdmp:exists(collection())
   => true

xdmp:forest(
$name as xs:string
)  as  xs:unsignedLong
Summary:

Returns the the ID of the forest specified as the parameter.

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 : A forest ID.

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 : A forest ID.

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  node()
Summary:

[DEPRECATED: use xdmp:document-get instead] Returns the document in the XML file specified by $path.

This function is deprecated and will be removed from a future release. Use xdmp:document-get instead.


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 MarkLogic Server is installed.
$default-namespace (optional): Default namespace for nodes in the first parameter. 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 Interface.

If neither "repair-full" nor "repair-none" is present, the default is specified by the XQuery version of the caller. In XQuery version 1.0 and 1.0-ml the default is "repair-none". In XQuery version 0.9-ml the default is "repair-full".


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: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:group-hosts(
[$name as xs:unsignedLong]
)  as  xs:unsignedLong*
Summary:

Returns the IDs of all hosts belonging to the group with the given ID. If no parameter is specified, it uses the group of the current host.

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

Example:
  xdmp:group-hosts(134722342511344334243)
  => 18263538320779601865
2760886727871312968

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

Returns the the name of the group with the given ID. Returns the name of the current group if no parameter is specified.

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

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

xdmp:group-servers(
[$name as xs:unsignedLong]
)  as  xs:unsignedLong*
Summary:

Returns the the IDs of all App Servers belonging to the group with the given ID. If no parameter is specified, it uses the group of the current host.

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

Example:
  xdmp:group-servers(xdmp:group("Default"))
   => 18263538320779601865
       2760886727871312968
       2714941248661564752

xdmp:groups( ) as xs:unsignedLong*
Summary:

Returns a sequence of the IDs of all the groups in the system.

Example:
  xdmp:groups()
   => 12363538320723601865
2350822345151312968
7891965607973455300
2314941134541564752

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:host(
[$name as xs:string]
)  as  xs:unsignedLong
Summary:

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

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

Example:
  xdmp:host("foo.example.com")
  => 15495681647217162987

xdmp:host-name(
$ID as xs:unsignedLong
)  as  xs:string
Summary:

Returns the the name of the host ID specified as the parameter. Returns the current host if no name is specified.

Parameters:
$ID : A host ID.

Example:
  xdmp:host-name(15495681647217162987)
  => foo.example.com

xdmp:hosts( ) as xs:unsignedLong*
Summary:

Returns a sequence of the IDs of all the hosts in the system.

Example:
  xdmp:hosts()
   => 18263538320779601865
2760886727871312968
1551965607977434000
2714941248661564752

xdmp:http-delete(
$uri as xs:string,
[$options as node()]
)  as  item()+
Summary:

Sends an http DELETE request to the http server specified in the URI to delete the specified resource. The server should respond if the request is to be completed, but a response is not guaranteed. Also, even if the server does respond, it does not guarantee that the request has been or will be completed.

Parameters:
$uri : The URI of the document to delete.
$options (optional): The options node for this request. The default value is (). The node for the xdmp:http-delete options must be in the xdmp:http namespace.

The xdmp:http-delete options include:

<headers>

A sequence of <name>value</name> pairs. The names can be anything, but many HTTP servers understand HTTP names such as content-type. These are turned into name:value HTTP headers. An error is raised if the child elements of the <headers> option are not of the form <name>value</name>.

<authentication>

The credentials and the authentication method to use for this request. This option has child elements for the username and password. The username is the name of the user to be authenticated on the http server. The password is that user's password. You can optionally specify a method attribute on the <authentication> element. If it is specified it must be either 'basic' or 'digest'. If a method is specified and the HTTP server requests a different type of authentication, then an error is raised. If the attribute is not specified, or matches the server's requested method, the authentication proceeds.

<timeout>

The amount of time, in seconds, to wait until the HTTP connection times out. The default value is the request timeout for the group.

Usage Notes:

The http functions only operate on URIs that use the http scheme; specifying a URI that does not begin with http:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).

Note the the xdmp:http-delete function simply sends a DELETE request to the specified web server; what happens with the DELETE request depends on the web server. The request does not delete a document from a MarkLogic Server database. To delete a document from a database, use the xdmp:document-delete function.


Example:
xdmp:http-delete("http://www.my.com/document.xhtml",
     <options xmlns="xdmp:http">
       <authentication method="basic">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
     </options>)
=> an optional response from the server



xdmp:http-get(
$uri as xs:string,
[$options as node()]
)  as  item()+
Summary:

Sends the http GET method to the specified URI. Returns the http response as well as whatever information is identified by the specified URI (for example, an html document).

Parameters:
$uri : The URI of the requested document.
$options (optional): The options node for this request. The default value is (). The node for the xdmp:http-get options must be in the xdmp:http namespace. This parameter can also include certain option elements (for example, repair, encoding, default-language) in the xdmp:document-load and xdmp:document-get namespaces.

The xdmp:http-get options include:

<headers>

A sequence of <name>value</name> pairs. The names can be anything, but many HTTP servers understand HTTP names such as content-type. These are turned into name:value HTTP headers. An error is raised if the child elements of the <headers> option are not of the form <name>value</name>.

<authentication>

The credentials and the authentication method to use for this request. This option has child elements for the username and password. The username is the name of the user to be authenticated on the http server. The password is that user's password. You can optionally specify a method attribute on the <authentication> element. If it is specified it must be either 'basic' or 'digest'. If a method is specified and the HTTP server requests a different type of authentication, then an error is raised. If the attribute is not specified, or matches the server's requested method, the authentication proceeds.

<timeout>

The amount of time, in seconds, to wait until the HTTP connection times out. The default value is the request timeout for the group.

Usage Notes:

The http functions only operate on URIs that use the http scheme; specifying a URI that does not begin with http:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).

If no encoding option (in the xdmp:document-get namespace) is specified, the encoding defaults to the encoding specified in the http header. If there is no encoding in the http header, the encoding defaults to UTF-8.

The first node in the output of xdmp:http-get is the response header from the http server.

The second node in the output of xdmp:http-get is the response from the http server. The response is treated as text, XML, or binary, depending on the content-type header sent from the http server. If the node is html, the header should indicate text/html, which is returned as a text document by default. The type of document is determined by the mimetypes mappings, and you can change the mappings in the Admin Interface as needed. If you happen to know that the response is XML, even if the header does not specify it as XML, and want to process the response as XML, you can wrap the response in an xdmp:unquote call to parse the response as XML. You could also use the <format>xml</format> option (in the xdmp:document-get namespace) to tell the API to treat the document as XML. Also, if you know the response is an HTML document, you can wrap the response in an xdmp:tidy call, which will treat the text as HTML, clean it up, and return an XHTML XML document.


Example:
xdmp:http-get("http://www.my.com/document.xhtml",
     <options xmlns="xdmp:http">
       <authentication method="basic">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
     </options>)
=> the response from the server as well as the specified document


Example:
xdmp:http-get("http://www.my.com/iso8859document.html",
     <options xmlns="xdmp:document-get">
       <encoding>iso-8859-1</encoding>
     </options>)[2]
=> The specified document, transcoded from ISO-8859-1
   to UTF-8 encoding.  This assumes the document is
   encoded in ISO-8859-1. Note that the encoding option
   is in the "xdmp:document-get" namespace.

Example:
xdmp:unquote(
  xdmp:http-get("http://www.my.com/somexml.xml")[2])
=> The specified xml document, parsed as XML by
   xdmp:unquote.  If the header specifies a 
   mimetype that is configured to be treated as
   XML, the xdmp:unquote call is not needed.  
   Alternately, you can treat the response as XML
   by specifying XML in the options node as 
   follows (note that the format option is in
   the "xdmp:document-get" namespace:

xdmp:http-get("http://www.my.com/somexml.xml",
	<options xmlns="xdmp:http-get">
	   <format xmlns="xdmp:document-get">xml</format>
	</options>)[2]

Example:
xdmp:tidy(
  xdmp:http-get("http://www.my.com/somehtml.html")[2])[2]
=> The specified html document, cleaned and transformed 
   to xhtml by xdmp:tidy.  The second node of the tidy 
   output is the xhtml node (the first node is the status).
   You could then perform XPath on the output to return 
   portions of the document. Note that the document (and 
   all of its elements) will be in the XHTML namespace, so 
   you need to specify the namespace in the XPath steps.  
   For example:
   
xquery version "1.0-ml";
declare namespace xh="http://www.w3.org/1999/xhtml";

xdmp:tidy(
  xdmp:http-get("http://www.my.com/somehtml.html")[2])[2]//xh:title


xdmp:http-head(
$uri as xs:string,
[$options as node()]
)  as  item()+
Summary:

Sends the http HEAD method to the specified URI. Returns the http response header for the specified URI.

Parameters:
$uri : The URI of the document whose response header is being requested.
$options (optional): The options node for this request. The default value is (). The node for the xdmp:http-head options must be in the xdmp:http namespace.

The xdmp:http-head options include:

<headers>

A sequence of <name>value</name> pairs. The names can be anything, but many HTTP servers understand HTTP names such as content-type. These are turned into name:value HTTP headers. An error is raised if the child elements of the <headers> option are not of the form <name>value</name>.

<authentication>

The credentials and the authentication method to use for this request. This option has child elements for the username and password. The username is the name of the user to be authenticated on the http server. The password is that user's password. You can optionally specify a method attribute on the <authentication> element. If it is specified it must be either 'basic' or 'digest'. If a method is specified and the HTTP server requests a different type of authentication, then an error is raised. If the attribute is not specified, or matches the server's requested method, the authentication proceeds.

<timeout>

The amount of time, in seconds, to wait until the HTTP connection times out. The default value is the request timeout for the group.

Usage Notes:

The http functions only operate on URIs that use the http scheme; specifying a URI that does not begin with http:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).


Example:
xdmp:http-head("http://www.my.com/document.xhtml",
     <options xmlns="xdmp:http">
       <authentication method="basic">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
     </options>)
=> the response header from the server



xdmp:http-options(
$uri as xs:string,
[$options as node()]
)  as  item()+
Summary:

Sends the http OPTIONS method to the specified URI. Returns the http response for the specified URI.

Parameters:
$uri : The URI of the document whose options response is being requested.
$options (optional): The options node for this request. The default value is (). The node for the xdmp:http-options options must be in the xdmp:http namespace.

The xdmp:http-options options include:

<headers>

A sequence of <name>value</name> pairs. The names can be anything, but many HTTP servers understand HTTP names such as content-type. These are turned into name:value HTTP headers. An error is raised if the child elements of the <headers> option are not of the form <name>value</name>.

<authentication>

The credentials and the authentication method to use for this request. This option has child elements for the username and password. The username is the name of the user to be authenticated on the http server. The password is that user's password. You can optionally specify a method attribute on the <authentication> element. If it is specified it must be either 'basic' or 'digest'. If a method is specified and the HTTP server requests a different type of authentication, then an error is raised. If the attribute is not specified, or matches the server's requested method, the authentication proceeds.

<timeout>

The amount of time, in seconds, to wait until the HTTP connection times out. The default value is the request timeout for the group.

Usage Notes:

The http functions only operate on URIs that use the http scheme; specifying a URI that does not begin with http:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).


Example:
xdmp:http-options("http://localhost:8000/",
     <options xmlns="xdmp:http">
       <authentication method="digest">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
     </options>)
=> the response from the HTTP server, for example:

<response xmlns="xdmp:http">
  <code>302</code>
  <message>Found</message>
  <headers>
    <location>/use-cases/</location>
    <server>MarkLogic</server>
    <content-length>0</content-length>
    <connection>close</connection>
  </headers>
</response>




xdmp:http-post(
$uri as xs:string,
[$options as node()]
)  as  item()+
Summary:

Sends the http POST request to the server.

Parameters:
$uri : The URI to which the data is to be posted.
$options (optional): The options node for this request. The default value is (). The node for the xdmp:http-post options must be in the xdmp:http namespace.

The xdmp:http-post options include:

<data>

This node can contain any string. Anything in the data node is sent as a string in the PUT or POST body. When POSTing to a web service, the data usually needs to be a SOAP XML structure. If you put an XML structure in the data element, it will return an error. Therefore, if you need the data to include a payload that is an XML structure, you should use xdmp:quote to encode the XML as a string. See the example below for a data node that uses xdmp:quote.

<headers>

A sequence of <name>value</name> pairs. The names can be anything, but many HTTP servers understand HTTP names such as content-type. These are turned into name:value HTTP headers. An error is raised if the child elements of the <headers> option are not of the form <name>value</name>.

<authentication>

The credentials and the authentication method to use for this request. This option has child elements for the username and password. The username is the name of the user to be authenticated on the http server. The password is that user's password. You can optionally specify a method attribute on the <authentication> element. If it is specified it must be either 'basic' or 'digest'. If a method is specified and the HTTP server requests a different type of authentication, then an error is raised. If the attribute is not specified, or matches the server's requested method, the authentication proceeds.

<timeout>

The amount of time, in seconds, to wait until the HTTP connection times out. The default value is the request timeout for the group.

Usage Notes:

The http functions only operate on URIs that use the http scheme; specifying a URI that does not begin with http:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).

If you expect the request body from this http function to be processed by another application (via a web service, for example), you must specify a content-type header. If no content-type header is specified, the content type defaults to application/x-www-form-urlencoded and the request body will be empty (the request is still accessible via the request fields).


Example:
xdmp:http-post("http://www.my.com/document.xhtml",
     <options xmlns="xdmp:http">
       <authentication method="basic">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
     </options>)
=> the response from the server as well as the specified document

Example:
(: Use xdmp:unquote to encode the XML as a string 
   because the <data> options element is a string :)
let $payload := xdmp:quote(
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'
  xmlns:my='urn:MyConnection'>
 <SOAP-ENV:Body>
   <my:LogOn>
     <my:User>user</my:User>
     <my:Password>pass</my:Password> 
     <my:Ticket>abc123</my:Ticket>
     <my:newData>1234</my:newData>
   </my:LogOn>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
)
return
xdmp:http-post("http://www.my.com/document.xhtml",
     <options xmlns="xdmp:http">
       <authentication method="basic">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
       <data>{$payload}</data>
     </options>)
=> the response from the server as well as the specified document


xdmp:http-put(
$uri as xs:string,
[$options as node()]
)  as  item()+
Summary:

Sends an HTTP PUT request to an HTTP server. The HTTP server should return a response, which will differ depending on the action the HTTP server takes for the PUT.

Parameters:
$uri : The URI to which the data is to be put.
$options (optional): The options node for this request. The default value is (). The node for the xdmp:http-put options must be in the xdmp:http namespace.

The xdmp:http-put options include:

<data>

This node can contain any string. Anything in the data node is sent as a string in the PUT or POST body.

<headers>

A sequence of <name>value</name> pairs. The names can be anything, but many HTTP servers understand HTTP names such as content-type. These are turned into name:value HTTP headers. An error is raised if the child elements of the <headers> option are not of the form <name>value</name>.

<authentication>

The credentials and the authentication method to use for this request. This option has child elements for the username and password. The username is the name of the user to be authenticated on the HTTP server. The password is that user's password. You can optionally specify a method attribute on the <authentication> element. If it is specified it must be either 'basic' or 'digest'. If a method is specified and the HTTP server requests a different type of authentication, then an error is raised. If the attribute is not specified, or matches the server's requested method, the authentication proceeds.

<timeout>

The amount of time, in seconds, to wait until the HTTP connection times out. The default value is the request timeout for the group.

Usage Notes:

The http functions only operate on URIs that use the http scheme; specifying a URI that does not begin with http:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).

If you expect the request body from this http function to be processed by another application (via a web service, for example), you must specify a content-type header. If no content-type header is specified, the content type defaults to application/x-www-form-urlencoded and the request body will be empty (the request is still accessible via the request fields).


Example:
xdmp:http-put("http://www.my.com/document.xhtml",
     <options xmlns="xdmp:http">
       <authentication method="basic">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
     </options>)
=> the response from the HTTP server as well as the specified document




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:invoke(
$path as xs:string,
[$vars as item()*],
[$options as node()]
)  as  item()*
Summary:

Returns the result of evaluating a module at the given path.

Parameters:
$path : The path of the module to be executed. The path is resolved against the root of the App Server evaluating the query, the Modules directory, or relative to the calling module. For details on resolving paths, see "Importing XQuery Modules and Resolving Paths" in the Developer's Guide.
$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.
$options (optional): The options node. The default value is (). The node must be in the xdmp:eval namespace. See the xdmp:eval section for a list of options.

Required Privilege:

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


Example:
  xdmp:invoke("http://example.com/modules/foo.xqy")
  => 2
Example:
  This example invokes a module using external variables.
  
  Assume you have a module in the modules database with a URI
  "http://example.com/application/module.xqy" containing the
  following code:

  xquery version "1.0-ml";
  declare namespace my="my-namespace-uri";
  declare variable $my:var as xs:string external;
  xdmp:log($my:var)

  Then you can call this module using xdmp:invoke as follows:

  xquery version "1.0-ml";
  declare namespace my="my-namespace-uri";
  xdmp:invoke("module.xqy", 
        (xs:QName("my:var"), "log this to ErrorLog.txt"), 
        <options xmlns="xdmp:eval">
          <modules>{xdmp:modules-database()}</modules>
	  <root>http://example.com/application/</root>
         </options>)
	 
  => Invokes an XQuery module from the modules database 
     with the URI http://example.com/application/module.xqy.
     The invoked module will then be executed, logging the 
     message sent in the external variable to the log file. 

xdmp:invoke-in(
$uri as xs:string,
$ID as xs:unsignedLong,
[$vars as item()*],
[$modules as xs:unsignedLong?],
[$root as xs:string?]
)  as  item()*
Summary:

[DEPRECATED: use xdmp:invoke with the database option instead] Returns the result of evaluating a module at the given path.

Parameters:
$uri : The path of the module to be executed. The path is resolved against the root of the App Server evaluating the query. The path must resolve to a main module (not a library module).
$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.
$modules (optional): The modules database containing the module to invoke. The empty sequence specifies the current modules database.
$root (optional): The root path for modules. The empty sequence specifies the current root.

Example:
  xdmp:invoke-in("http://example.com/modules/foo.xqy",2348790529)
  => 2

xdmp:log(
$msg as item()*,
[$level as xs:string]
)  as  empty-sequence()
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. The default level is "info".

Example:
  xdmp:log("AAAA")
  => ()

xdmp:log-level( ) as xs:string
Summary:

Retrieves the current server log level.

Example:
  xdmp:log-level()
  => finest

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:modules-database( ) as xs:unsignedLong
Summary:

Returns the database ID of the modules database. Returns 0 if the current App Server uses the file system for its modules.

Example:
  xdmp:modules-database()
  => 8447094497219470018

xdmp:modules-root( ) as xs:string
Summary:

Returns the current root path for modules.

Example:
  xdmp:modules-root()
   => Docs

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-database(
$node as node()
)  as  xs:unsignedLong?
Summary:

Returns the database id where the parameter is stored. If the specified node does not come from a document in a database, then xdmp:node-database returns an empty list.

Parameters:
$node : The node whose database is returned.

Example:
  xdmp:node-database(doc("http://marklogic.com/document"))
   => 18384173956586417397

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 Mark Logic 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:node-uri(
$node as node()
)  as  xs:string?
Summary:

Returns the document-uri property of the parameter or its ancestor.

Parameters:
$node : The node whose URI is returned.

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(),
[$include-document as xs:boolean]
)  as  xs:string
Summary:

Returns a string whose value corresponds to the path of the node.

Parameters:
$node : The node whose path is returned.
$include-document (optional): If true, then the path is presented with a leading doc(..)/.., otherwise the path is presented as /...

Example:
  let $arg := <a><b><c>ccc</c></b>
                <b>bbb</b></a>
  return xdmp:path($arg/b[1]/c)
  => "/a/b[1]/c"

xdmp:platform( ) as xs:string
Summary:

Returns the operating-system platform upon which MarkLogic Server is running ("solaris", "winnt", or "linux").

Example:
  xdmp:platform()
   => "winnt"

xdmp:product-edition( ) as xs:string
Summary:

Returns the current Mark Logic product edition.

Example:
  xdmp:product-edition()
   => "Standard"

xdmp:query-meters( ) as element()
Summary:

Returns the current value of the resource meters for this query sequence.

Usage Notes:

The resource meters returned include:

elapsed-time
The time elapsed since the start of the processing of this query, in the form of a duration.
list-cache-hits
The number of successful list cache lookups. The list cache holds search termlists used to accelerate path expressions and text searches.
list-cache-misses
The number of unsuccessful list cache lookups. Each unsuccessful list cache lookup was followed by a disk access to load the search termlist into the cache.
in-memory-list-hits
The number of successful list lookups in in-memory stands.
expanded-tree-cache-hits
The number of successful expanded tree cache lookups. The expanded tree cache cache holds XML document data in the expanded representation used by the XQuery evaluator.
expanded-tree-cache-misses
The number of unsuccessful expanded tree cache lookups. Each unsuccessful expanded tree lookup was followed by a compressed tree cache lookup to load the expanded tree into the cache.
compressed-tree-cache-hits
The number of successful compressed tree cache lookups. The compressed tree cache holds XML document data in the compressed representation stored on disk.
compressed-tree-cache-misses
The number of unsuccessful compressed tree cache lookups. Each unsuccessful compressed tree cache lookup was followed by a disk access to load the compressed tree into the cache.
in-memory-compressed-tree-hits
The number of successful compressed tree lookups in in-memory stands.
value-cache-hits
The number of successful value cache lookups. The value cache is a transient cache that exists only for the duration of one query. It holds typed values, and is used to accelerate the frequent conversion of nodes to typed values.
value-cache-misses
The number of unsuccessful value cache lookups. Each unsuccessful value cache lookup was followed by a conversion of an XML node to a typed value.
regexp-cache-hits
The number of successful regular expression cache lookups. The regular expression cache is a transient cache that exists only for the duration of one query. It holds compiled regular expressions, and is used to accelerate the frequent use of regular expressions during the evaluation of a query.
regexp-cache-misses
The number of unsuccessful regular expression cache lookups. Each unsuccessful regular expression cache lookup was followed by a compilation of a regular expression from source text.
link-cache-hits
The number of successful link cache lookups. The link cache is a transient cache that exists only for the duration of one query. It holds pointers to expanded trees, and is used to accelerate the frequent dereferencing of link nodes.
link-cache-misses
The number of unsuccessful link cache lookups. Each unsuccessful link cache lookup was followed by a search for the link target tree.
fragments-added
The number of XML fragments added to the database by an update.
fragments-deleted
The number of XML fragments deleted from the database by an update.
fs-program-cache-hits
The number of module cache hits from the entire program made from modules on the file system.
fs-program-cache-misses
The number of module cache misses from the entire program made from modules on the file system.
db-program-cache-hits
The number of module cache hits from the entire program made from modules in a database (may contain library modules from the special Modules directory).
db-program-cache-misses
The number of module cache misses from the entire program made from modules in a database (may contain library modules from the special Modules directory).
fs-main-module-sequence-cache-hits
The number of main module cache hits from main modules on the file system.
fs-main-module-sequence-cache-misses
The number of main module cache misses from main modules on the file system.
db-main-module-sequence-cache-hits
The number of main module cache hits from main modules in a database.
db-main-module-sequence-cache-misses
The number of main module cache misses from main modules in a database.
fs-library-module-cache-hits
The number of library module cache hits from library modules on the file system.
fs-library-module-cache-misses
The number of library module cache misses from library modules on the file system.
db-library-module-cache-hits
The number of library module cache hits from library modules from the modules database.
db-library-module-cache-misses
The number of library module cache misses from library modules from the modules database.

Some meters are broken down by fragment root and document URI:

fragments
A sequence of fragment elements, each containing:
root
The fragment root name.
expanded-tree-cache-hits
A count of successful expanded tree cache lookups for this fragment root.
expanded-tree-cache-misses
A count of unsuccessful expanded tree cache lookups for this fragment root.
documents
A sequence of document elements, each containing:
uri
The document URI.
expanded-tree-cache-hits
A count of successful expanded tree cache lookups for this document URI.
expanded-tree-cache-misses
A count of unsuccessful expanded tree cache lookups for this document URI.

Example:
  xdmp:query-meters();
  => 
  <qm:query-meters 
   xsi:schemaLocation="http://marklogic.com/xdmp/query-meters 
       query-meters.xsd" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:qm="http://marklogic.com/xdmp/query-meters">
    <qm:elapsed-time>PT0.22S</qm:elapsed-time>
    <qm:requests>1</qm:requests>
    <qm:list-cache-hits>0</qm:list-cache-hits>
    <qm:list-cache-misses>0</qm:list-cache-misses>
    <qm:in-memory-list-hits>0</qm:in-memory-list-hits>
    <qm:expanded-tree-cache-hits>0
       </qm:expanded-tree-cache-hits>
    <qm:expanded-tree-cache-misses>0
       </qm:expanded-tree-cache-misses>
    <qm:compressed-tree-cache-hits>0
       </qm:compressed-tree-cache-hits>
    <qm:compressed-tree-cache-misses>0
       </qm:compressed-tree-cache-misses>
    <qm:in-memory-compressed-tree-hits>0
       </qm:in-memory-compressed-tree-hits>
    <qm:value-cache-hits>0</qm:value-cache-hits>
    <qm:value-cache-misses>0</qm:value-cache-misses>
    <qm:regexp-cache-hits>0</qm:regexp-cache-hits>
    <qm:regexp-cache-misses>0</qm:regexp-cache-misses>
    <qm:link-cache-hits>0</qm:link-cache-hits>
    <qm:link-cache-misses>0</qm:link-cache-misses>
    <qm:fragments-added>0</qm:fragments-added>
    <qm:fragments-deleted>0</qm:fragments-deleted>
    <qm:fs-program-cache-hits>1</qm:fs-program-cache-hits>
    <qm:fs-program-cache-misses>0</qm:fs-program-cache-misses>
    <qm:db-program-cache-hits>0</qm:db-program-cache-hits>
    <qm:db-program-cache-misses>0</qm:db-program-cache-misses>
    <qm:fs-main-module-sequence-cache-hits>0
       </qm:fs-main-module-sequence-cache-hits>
    <qm:fs-main-module-sequence-cache-misses>0
       </qm:fs-main-module-sequence-cache-misses>
    <qm:db-main-module-sequence-cache-hits>0
       </qm:db-main-module-sequence-cache-hits>
    <qm:db-main-module-sequence-cache-misses>0
       </qm:db-main-module-sequence-cache-misses>
    <qm:fs-library-module-cache-hits>0
       </qm:fs-library-module-cache-hits>
    <qm:fs-library-module-cache-misses>0
       </qm:fs-library-module-cache-misses>
    <qm:db-library-module-cache-hits>0
       </qm:db-library-module-cache-hits>
    <qm:db-library-module-cache-misses>0
       </qm:db-library-module-cache-misses>
    <qm:fragments/>
    <qm:documents/>
  </qm:query-meters> 
Example:

xquery version "1.0-ml";
declare namespace qm="http://marklogic.com/xdmp/query-meters";

fn:count(collection()),
xdmp:query-meters()/qm:elapsed-time

=> The count of the number of documents in the database followed by
   the elapsed-time element of the xdmp:query-trace XML output:

153
<qm:elapsed-time xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                 xmlns:qm="http://marklogic.com/xdmp/query-meters">
		 PT0.04S</qm:elapsed-time>


xdmp:query-trace(
$enabled as xs:boolean
)  as  empty-sequence()
Summary:

Enables or disables tracing of this query. When query tracing is enabled, "info" level messages are logged detailing the search optimizations performed.

Parameters:
$enabled : Specify true to enable query tracing, false to disenable query tracing.

Usage Notes:

Search optimizations are performed in three phases:

the path analysis phase
In this phase a path expression is analyzed to determine whether it can be executed in whole or in part through an optimized search. Each individual component of the path is analyzed to see if it is searchable. The searchablity of each path component is logged.
the search constraint gathering phase
In this phase, search constraints are gathered from the path expression components. The number of constraints contributed by each path component is logged.
the search execution phase
In this phase, a search is performed using the gathered constraints. The actual number of fragments selected for filtering is logged.

Example:
  xdmp:query-trace(true());
  => ()

xdmp:quote(
$arg as item()*,
[$options as node()]
)  as  xs:string
Summary:

Returns the unevaluated serialized representation of the input parameter as a string.

Parameters:
$arg : Input to be quoted.
$options (optional): The options node for this quote operation. The default value is (). The node for the xdmp:quote options must be in the xdmp:quote namespace.

The xdmp:quote options include:

<output-encoding>

Specifies the encoding to use for this quote operation. This is only used to escape characters that cannot be represented.

<output-sgml-character-entities>

Specifies if character entities should be output upon serialization of the XML. Valid values are normal, none, math, and pub. By default (that is, if this option is not specified), no SGML entities are serialized on output, unless the App Server is configured to output SGML character entities.

Example:
  let $arg := <a>aaa</a>
  return ($arg, xdmp:quote($arg))
  => (<a>aaa</a>, "<a>aaa</a>")

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:request( ) as xs:unsignedLong
Summary:

Returns the unique key of the current request.

Example:
  xdmp:request()
   => 18263538320779601865

xdmp:request-timestamp( ) as xs:unsignedLong?
Summary:

Returns the system timestamp for this request if the request is a query statement. Returns the empty sequence if the current request is an update statement.

Usage Notes:

The xdmp:request-timestamp function returns the system timestamp that is in effect for current query. This timestamp will remain unchanged for the duration of the query. If you want to get the most recent system timestamp external to the current running context during an update statement (for example, if your query takes a long time to run, and there are other updates occurring in your database while your update statement is running), you can use xdmp:eval to evaluate a separate query statement that returns the system timestamp at the time the xdmp:eval query is evaluated.

Example:
  xdmp:request-timestamp()
   => 1234567

xdmp:rethrow( ) as empty-sequence()
Summary:

Rethrow the currently caught error.

Example:
xdmp:rethrow()

xdmp:schema-database( ) as xs:unsignedLong
Summary:

Returns the database ID of the schema database associated with the current database.

Usage Notes:

To run queries against the schema database, you can specify the xdmp:schema-database() function as the second parameter to xdmp:eval-in().

Example:
  xdmp:schema-database()
  => 15467547981724877000

xdmp:security-database( ) as xs:unsignedLong
Summary:

Returns the database ID of the security database associated with the current database.

Usage Notes:

To run queries against the security database, you can specify the xdmp:security-database() function as the second parameter to xdmp:eval-in().

Example:
  xdmp:security-database()
  => 8447094497219470018

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

Returns the the ID(s) of the App Server specified in the parameter. Returns the ID of the current App Server if no parameter is specified.

Parameters:
$name (optional): The name of the App Server. The default value is the name of the current App Server.

Example:
  xdmp:server("foo.example.com")
  => 15495681647217162987

xdmp:server-name(
$id as xs:unsignedLong
)  as  xs:string
Summary:

Return the name of the App Server with the given ID.

Parameters:
$id : A App Server ID.

Example:
xdmp:server-name(845637403676198)
=> "Docs"

xdmp:servers( ) as xs:unsignedLong*
Summary:

Returns a sequence of the IDs of all the App Servers in the system.

Example:
  xdmp:servers()
   => 18263538320779601865
2760886727871312968
1551965607977434000
2714941248661564752

xdmp:set(
$variable as item()*,
$expr as item()*
)  as  empty-sequence()
Summary:

Set the value of a variable to the specified expression. The xdmp:set command allows you to introduce changes to the state (side effects) of a query by changing the value of a variable to something other than what it is bound to.

Parameters:
$variable : A variable to set.
$expr : A value to set the variable.

Usage Notes:

When a variable is bound to a sequence in a for loop, and when that variable is changed by xdmp:set in the return clause, the change only effects the value for one iteration of the for loop at a time; when the next value is sent to the return clause, it is set to the next value in the sequence specified in the for clause. The value changes only after the xdmp:set call is made.

Example:
(: set the value of the variable $x 
   to 1234 and then print out $x :)

let $x := 12
return
(xdmp:set($x, 1234), $x)

=> 1234
Example:
(: set the value of the variable $x 
   to 5 and then print out $x for 
   each value of $y :)

for $x in (1, 2)
  for $y in ($x, $x)
return
($y, xdmp:set($x, 5), $x)

=> (1, 5, 1, 5, 2, 5, 2, 5)

Example:
(: note the effect on $z of changing the 
   value of $x :)

for $x in (1, 2)
  for $y in (3,4)
    for $z in ($x, $x)
return
($z, xdmp:set($x, 5))

=> (1, 1, 5, 5, 2, 2, 5, 5)

Example:
(: every time the name of the input node changes,
   output the new name  :)

let $n := ()
for $i in (<x>1</x>, <x>2</x>, <y>3</y>)
return (
   if (name($i) eq $n) 
   then () 
   else (xdmp:set($n, name($i)), $n)
  , data($i)
)

=> (x, 1, 2, y, 3)


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:spawn(
$path as xs:string,
[$vars as item()*],
[$options as node()]
)  as  empty-sequence()
Summary:

Place the specified module on the task queue for evaluation.

Parameters:
$path : The path, relative to the specified root, of the module to be executed. For more details on resolving paths, see "Importing XQuery Modules and Resolving Paths" in the Developer's Guide.
$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.
$options (optional): The options node. The default value is (). The node must be in the xdmp:eval namespace. See the xdmp:eval section for a list of options.

Required Privilege:

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


Usage Notes:

The xdmp:spawn function places the specified XQuery module in the task queue to be processed. The module will be evaluated when the task server has the available resources to process it. The tasks are processed in the order in which they are added to the queue.

Once xdmp:spawn is called, it cannot be rolled back, even if the transaction from which it is called does not complete. Therefore, use care or preferably avoid calling xdmp:spawn from a module that is performing an update transaction. Once a module is spawned, its evaluation is completely asynchronous of the statement in which xdmp:spawn was called. Consequently, if you call xdmp:spawn from a module that is updating a document, and if the update ends up retrying (for example, if a deadlock is detected), then the entire module is re-evaluated and the xdmp:spawn call is therefore called again. This will only happen in update statements, not in query statements. For details on how transactions work in MarkLogic Server, see "Understanding Transactions in MarkLogic Server" in the Developer's Guide.


Example:
  xdmp:spawn("module.xqy", (), 
        <options xmlns="xdmp:eval">
          <modules>{xdmp:modules-database()}</modules>
	  <root>http://example.com/application/</root>
         </options>)
	 
  => Puts the module from the modules database with the 
     URI http://example.com/application/module.xqy 
     in the task server queue.

xdmp:spawn-in(
$path as xs:string,
$ID as xs:unsignedLong,
[$vars as item()*],
[$modules as xs:unsignedLong?],
[$root as xs:string?]
)  as  empty-sequence()
Summary:

[DEPRECATED: use xdmp:spawn with the database option instead] Place the specified module on the task queue for evaluation. It will be evaluated in the given database.

Parameters:
$path : The path, relative to the specified root, of the module to be executed.
$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.
$modules (optional): The modules database that contains the module to invoke. The empty sequence specifies the current modules database.
$root (optional): The root path for modules. The empty sequence specifies the current root.

Usage Notes:

The xdmp:spawn-in function places the specified XQuery module in the task queue to be processed. The module will be evaluated when the task server has the available resources to process it. The tasks are processed in the order in which they are added to the queue.


Example:
  xdmp:spawn-in("example.xqy",
                324398742983742,
                (),
                xdmp:modules-database(),
                "http://example.com/application/")
  => ()
  Puts the module from the modules database with the 
  URI http://example.com/application/module.xqy 
  in the task server queue. The module will be 
  executed in the context of the database with
  an ID of 324398742983742.

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:subbinary(
$source as binary(),
$starting-location as xs:double,
[$length as xs:double]
)  as  binary()
Summary:

Returns a binary node made up of a subset of the given binary node.

Parameters:
$source : A binary node whose subset will be returned
$starting-location : The new binary node starts at the byte position indicated by starting-location. The first byte is at location 1.
$length (optional): The length in bytes of the new binary node.

Usage Notes:

Usage is exactly like fn:substring except that it applies to a binary node rather than a string.


Example:
  data(xdmp:subbinary(binary { xs:hexBinary("DEADBEEF") }, 3, 2))
  => xs:hexBinary("BEEF")

xdmp:trace(
$name as xs:string,
$value as item()*
)  as  empty-sequence()
Summary:

Signal a trace event. If trace events are activated and the event is enabled, the trace event is logged.

Parameters:
$name : The trace event name.
$value : The trace event data.

Example:
  xdmp:trace("My Application Event",$my-application-data)
  => ()

xdmp:triggers-database( ) as xs:unsignedLong
Summary:

Returns the database ID of the triggers database associated with the current database.

Example:
  xdmp:triggers-database()
  => 8447094497219470018

xdmp:unpath(
[$expr as xs:string]
)  as  item()*
Summary:

Evaluate a string as an XPath and return the corresponding node(s). Any value that is the result of xdmp:path is a valid input to xdmp:unpath. To evaluate non-XPath expressions, use xdmp:value.

Parameters:
$expr (optional): The XPath expression string to evaluate. The XPath expression must be of the form returned by xdmp:path.

Required Privilege:

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

Example:
  xdmp:unpath("/bookstore/book/title")
  => <title>Querying XML</title>
  
Example:

The following example shows how you can use xdmp:unpath and specify namespace bindings that are not in the current query scope.

xquery version "1.0-ml";

let $doc := <html xmlns="http://www.w3.org/1999/xhtml">
              <body><p>This is a document</p></body>
            </html>
let $namespaces:= ("xh", "http://www.w3.org/1999/xhtml")
let $xpath-str := "$doc/xh:body/xh:p"
return xdmp:with-namespaces($namespaces, xdmp:unpath($xpath-str))

=> <p xmlns="http://www.w3.org/1999/xhtml">This is a document</p>
  

xdmp:unquote(
$arg as xs:string,
[$default-namespace as xs:string],
[$options as xs:string*]
)  as  document-node()+
Summary:

Parses a string as XML, returning one or more document nodes.

Parameters:
$arg : Input to be unquoted.
$default-namespace (optional): Default namespace for nodes in the first parameter.
$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.
"default-language=xx"
If the root element node specified in the first parameter does not already have an xml:lang attribute, the language to specify in an xml:lang attribute on the root element node. If default-language is not specified, then nothing is added to the root element node. Some examples are default-language=en and default-language=fr.

Usage Notes:

If no format is specified in $options, it is XML.

If neither "repair-full" nor "repair-none" is present, the default is specified by the XQuery version of the caller. In XQuery version 1.0 and 1.0-ml the default is "repair-none". In XQuery version 0.9-ml the default is "repair-full".

If $arg is the empty string, xdmp:unquote returns an empty document node.


Example:
  xdmp:unquote("<foo/>")
  => <foo/>
  It returns this as a document node.
Example:
  xdmp:unquote('<foo>hello</foo>', "", 
          ("repair-none", "default-language=en"))
  => <foo xml:lang="en">hello</foo>
  It returns this as a document node and does
  not perform tag repair on the node.

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

Returns the content type of the given URI as matched in the mimetypes configuration. xdmp:content-type continues to work too.

Parameters:
$uri : The document URI.

Example:
  xdmp:uri-content-type("example.txt")
  => text/plain
Example:
  xdmp:uri-content-type("example.xml")
  => text/xml
Example:
  xdmp:uri-content-type("example.doc")
  => application/msword

xdmp:uri-format(
$uri as xs:string
)  as  xs:string
Summary:

Returns the format of the given URI as matched in the mimetypes configuration.

Parameters:
$uri : The document URI.

Example:
  xdmp:uri-format("example.txt")
  => text
Example:
  xdmp:format("example.xml")
  => xml

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> 

xdmp:value(
[$expr as xs:string]
)  as  item()*
Summary:

Evaluate an expression in the context of the current evaluating statement. This differs from xdmp:eval in that xdmp:value preserves all of the context from the calling query, so you do not need to re-define namespaces, variables, and so on. Although the expression retains the context from the calling query, it is evaluated in its own transaction with same-statement isolation.

Parameters:
$expr (optional): The string representing an expression to evaluate.

Required Privilege:

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

Usage Notes:

You can only evaluate expressions with xdmp:value; no prolog definitions (namespace declarations, function definitions, module imports, and so on) are allowed.

If the expression references something not in the context of either the calling query or the value expression, then an error is thrown. For example, the following throws an undefined variable exception:

xdmp:value("$y")

Example:
  let $var := 5 
  return
  xdmp:value("$var")
  => 5
  

xdmp:version( ) as xs:string
Summary:

Returns the current MarkLogic Server version.

Example:
  xdmp:version()
   => "3.2-1"

xdmp:with-namespaces(
$nsbindings as xs:string*,
$expr as item()*
)  as  item()*
Summary:

Evaluates the expression in the context of a specific set of namespace bindings.

Parameters:
$nsbindings : An alternating sequence of prefixes and URIs. Each prefix is bound to the following URI.
$expr : An expression to evaluate in the context of the given namespace bindings.

Required Privilege:

http://marklogic.com/xdmp/privileges/xdmp-with-namespaces

Example:

let $version := "1.2" return 
xdmp:with-namespaces(("p", fn:concat("http://marklogic.com/p/",$version)),
   <p:bar/>
)  

Returns:

   <p:bar xmlns:p="http://marklogic.com/p/1.2"/>
  

xdmp:xquery-version( ) as xs:string
Summary:

Returns the XQuery language version of the calling module. Currently supported XQuery versions are:
  • "0.9-ml": The legacy Mark Logic XQuery version. This was the only XQuery version available on MarkLogic Server 3.2 and earlier. It is based on the May 2003 XQuery Draft Recommendation, with Mark Logic extensions
  • "1.0-ml": XQuery version 1.0, with Mark Logic extensions. This is the preferred version of XQuery beginning with release 4.0.
  • "1.0": Strict XQuery version 1.0. This XQuery version complies as closely as possible with the published XQuery 1.0 specification.

Example:
  xdmp:xquery-version()
   => "1.0-ml"