MarkLogic Server
XQUERY API DOCUMENTATION
3.2
This page was generated
August 7, 2008
7:40 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:base64-decode Converts base64-encoded string to plaintext.
xdmp:base64-encode Converts plaintext into base64-encoded string.
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] Returns the document in the XML file specified by $path.
xdmp:hash32 Returns the 32-bit hash of a string.
xdmp:hash64 Returns the 64-bit hash of a string.
xdmp:hex-to-integer Parses a hexadecimal string, returning an integer.
xdmp: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-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:modules-database Returns the database ID of the modules database.
xdmp:modules-root Returns the current root path for modules.
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 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: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 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: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: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:version Returns the current MarkLogic Server version.
Function Detail
xdmp:access(
$uri as xs:string,
$action as xs:string
)  as  xs:boolean
Summary:

Returns whether a given action on the specified document URI would succeed.

Parameters:
$uri : The document URI.
$action : The type of access: "create", "insert", "update", or "execute".

Example:
  xdmp:access(
         "http://example.com/foo.xml",
         "create")
   => true()

xdmp: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: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:
  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
)  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.

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. 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 and ISO-8859-1. 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.

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 console.

If neither "repair" option is specified, malformed XML content will be repaired.

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",
         expanded-QName("http://examples.com/","priority"))
   => <priority xmlns="http://examples.com/">5</priority>

xdmp:document-get-quality(
$uri as xs:string
)  as  xs:integer?
Summary:

Returns the quality of the specified document if the document exists. Otherwise, returns the empty sequence.

Parameters:
$uri : The URI of the document in question.

Example:
  xdmp:document-get-quality("example.xml")
  => 10

xdmp:document-locks(
[$uri as xs:string*]
)  as  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:
<