<apidoc:module name="Extensions" category="Extension" lib="xdmp" xmlns:apidoc="http://marklogic.com/xdmp/apidoc"><apidoc:summary category="Extension" lib="xdmp" access="public">
   <p xmlns="http://www.w3.org/1999/xhtml">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.</p>
 </apidoc:summary><apidoc:summary category="map" lib="map" access="public">
   <p xmlns="http://www.w3.org/1999/xhtml">The map built-in functions are used to create maps.  Maps store
   name-value pairs in an in-memory data structure.
   You can also persist a map to disk by storing it in a document.
   Some programming languages implement maps using hash tables, but these
   map functions make it convenient for you to create and update your
   own maps.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">Maps are represented using the <code>map:map</code> XQuery primitive 
   type.  When you serialize an object of <code>map:map</code> type, it
   serializes to an XML node in the <code>http://marklogic.com/xdmp/map</code>
   namespace.</p>
 </apidoc:summary><apidoc:summary category="Extension" lib="xdmp" subcategory="Function Values">
   <p xmlns="http://www.w3.org/1999/xhtml">The function values functions allow you to pass a function value
   as a parameter to another function.  You can also pass in the location
   of the implementation of a function, allowing the caller to
   specify a different version of a function to use in the context of
   making that function.</p>
 </apidoc:summary><apidoc:summary category="Extension" lib="xdmp" subcategory="MarkLogic Server">
 <p xmlns="http://www.w3.org/1999/xhtml">The MarkLogic Server extension functions are XQuery extensions that
 return MarkLogic Server-specific information, such as the version of 
 MarkLogic Server, the IDs of the hosts in the cluster, and so on. </p>
 </apidoc:summary><apidoc:summary category="Extension" lib="xdmp" subcategory="Extension">
 <p xmlns="http://www.w3.org/1999/xhtml">The extension functions provide miscellaneous extensions to XQuery.</p>
 </apidoc:summary><apidoc:summary category="Extension" lib="xdmp" subcategory="HTTP">
 <p xmlns="http://www.w3.org/1999/xhtml">The HTTP functions allow you to make various HTTP calls from
 within your XQuery program.</p>
 </apidoc:summary><apidoc:summary category="Extension" lib="xdmp" subcategory="Search">
 <p xmlns="http://www.w3.org/1999/xhtml">The search extension functions complement the Search Built-in functions.</p>
 </apidoc:summary><apidoc:summary category="Extension" lib="xdmp" subcategory="XML">
 <p xmlns="http://www.w3.org/1999/xhtml">The XML extension functions provide XML functionality such as 
 parsing a string as XML.</p>
 </apidoc:summary><apidoc:summary category="Extension" lib="xdmp" subcategory="XQuery Context">
 <p xmlns="http://www.w3.org/1999/xhtml">The XQuery Context functions are XQuery extensions that allow
 you to start a new query context, manipulate the current context, or
 get information about the current context.</p>
 </apidoc:summary><apidoc:summary category="Extension" subcategory="Documents, Directories, Properties, and Locks">
 <p xmlns="http://www.w3.org/1999/xhtml">The Documents, Directories, Properties, and Locks functions are XQuery built-in
 extension functions that get information from documents, directories, 
 properties, and locks from MarkLogic Server.  All of these are stored
 as fragments in a database.</p>
 </apidoc:summary><apidoc:function name="strftime" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Formats a dateTime value using POSIX strftime.  This function uses
  the POSIX strftime system call in the way it is implemented on each 
  platform.  For other XQuery functions that have more functionality 
  (for example, for things like timezones), use one or more if the 
  various XQuery or XSLT standard functions such as 
  <a href="#fn:format-dateTime" xmlns="http://www.w3.org/1999/xhtml"><code>fn:format-dateTime</code></a>.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="format" type="xs:string" optional="false">
    The strftime format string.
  </apidoc:param>
      <apidoc:param name="value" type="xs:dateTime" optional="false">
    The dateTime value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:usage>
 <p xmlns="http://www.w3.org/1999/xhtml">The supported format strings differ for different platforms.  For the 
 supported format strings for Windows, see the following link:</p>
 <p xmlns="http://www.w3.org/1999/xhtml"><a href="http://msdn2.microsoft.com/en-us/library/fe06s4ak(VS.80).aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/fe06s4ak(VS.80).aspx</a></p>
 <p xmlns="http://www.w3.org/1999/xhtml">For the supported format strings for Solaris, see the following link:</p>
 <p xmlns="http://www.w3.org/1999/xhtml"><a href="http://docs.sun.com/app/docs/doc/817-5438/6mkt5pcec?a=view" target="_blank">http://docs.sun.com/app/docs/doc/817-5438/6mkt5pcec?a=view</a></p>
 <p xmlns="http://www.w3.org/1999/xhtml">For the supported format strings for Linux, see the following link:</p>
 <p xmlns="http://www.w3.org/1999/xhtml"><a href="http://linux.about.com/library/cmd/blcmdl3_strftime.htm" target="_blank">http://linux.about.com/library/cmd/blcmdl3_strftime.htm</a></p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:strftime("%a, %d %b %Y %H:%M:%S",current-dateTime())
   =&gt; Tue, 08 Apr 2003 17:21:37
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="exists" type="builtin" lib="xdmp" category="Extension" subcategory="Search" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.  
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="expression" type="item()*" optional="false">
    The expression to check.
    This must be a partially searchable XPath expression
    or a <code xmlns="http://www.w3.org/1999/xhtml">cts:search()</code> expression.    
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:integer</apidoc:return>
    <apidoc:usage>
    <p xmlns="http://www.w3.org/1999/xhtml">Queries that use <code>xdmp:exists</code> require that the XPath 
    expression searched is partially searchable. 
    A <em>partially searchable</em> XPath expression is one whose first step 
    is searchable. You can use <code>xdmp:query-trace()</code> to determine 
    if a step is searchable.  If there are no entries in the 
    <code>xdmp:query-trace()</code> output indicating that the first step 
    is <code>unsearchable</code>, then the expression is partially searchable 
    and you can perform an <code>xdmp:exists</code> operation on it.</p>
    <p xmlns="http://www.w3.org/1999/xhtml">Calling <code>xdmp:exists</code> on an expression is the same as
    calling <code>xdmp:estimate</code> on the expression with a maximum of 1.
    For example, the following are equivalent:<br/>
    <pre xml:space="preserve">
     xdmp:exists(cts:search(collection(), "foo"))
     
       is equivalent to:
     
     xs:boolean(xdmp:estimate(cts:search(collection(), "foo"), 1)) </pre></p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:exists(collection())
   =&gt; true
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="estimate" type="builtin" lib="xdmp" category="Extension" subcategory="Search" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.  
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="expression" type="item()*" optional="false">
    The expression to estimate.
    This must be a partially searchable XPath expression
    or a <code xmlns="http://www.w3.org/1999/xhtml">cts:search()</code> expression.    
  </apidoc:param>
      <apidoc:param name="maximum" type="xs:double?" optional="true">
    The maximum value to return.
    Stop selecting fragments if this number is reached.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:integer</apidoc:return>
    <apidoc:usage>
    Queries that use <code xmlns="http://www.w3.org/1999/xhtml">xdmp:estimate</code> require that the XPath 
    expression searched is partially searchable. 
    A <em xmlns="http://www.w3.org/1999/xhtml">partially searchable</em> XPath expression is one whose first step 
    is searchable. You can use <code xmlns="http://www.w3.org/1999/xhtml">xdmp:query-trace()</code> to determine 
    if a step is searchable.  If there are no entries in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:query-trace()</code> output indicating that the first step 
    is <code xmlns="http://www.w3.org/1999/xhtml">unsearchable</code>, then the expression is partially searchable 
    and you can perform an <code xmlns="http://www.w3.org/1999/xhtml">xdmp:estimate</code> operation on it.
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:estimate(collection())
   =&gt; 10476
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="plan" type="builtin" lib="xdmp" category="Extension" subcategory="Search" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns an XML element recording information about how the given 
  expression will be processed by the index.  The information is a
  structured representation of the information provided in the error log
  when query trace is enabled.  The query will be processed up to the
  point of getting an estimate of the number of fragments returned by the
  index.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="expression" type="item()*" optional="false">
    The expression to estimate.
    This must be a partially searchable XPath expression
    or a <code xmlns="http://www.w3.org/1999/xhtml">cts:search()</code> expression.    
  </apidoc:param>
      <apidoc:param name="maximum" type="xs:double?" optional="true">
    The maximum value to return.
    Stop selecting fragments if this number is reached.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>element()</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">The output from <code>xdmp:plan</code> will vary depending on various index
  settings.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Running an <code>xdmp:plan</code> on a search is similar to running an 
  <code>xdmp:estimate</code> on a search, but it returns a report on the
  search instead of just an estimate. As part of the report, the 
  <code>qry:result</code> element includes the estimate.
  If the search expression argument cannot be run in the 
  plan because it is not partially searchable, then an 
  <code>XDMP-UNSEARCHABLE</code> exception is returned as part of the
  <code>xdmp:plan</code> output. </p>
  <p xmlns="http://www.w3.org/1999/xhtml">If you are running a search using the search API 
  (for example, <code>search:search</code>), use the  
  option <code>&lt;return-plan&gt;true&lt;/return-plan&gt;</code> in your
  search API options node.
  </p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:plan(cts:search(fn:doc(),cts:word-query("cat")))
   =&gt; 
&lt;qry:query-plan xmlns:qry="http://marklogic.com/cts/query"&gt;
  &lt;qry:info-trace&gt;xdmp:eval("xquery version &amp;amp;quot;1.0-ml&amp;amp;quot;;&amp;amp;#13;
  &amp;amp;#10;xdmp:plan(cts:search...", (), &amp;lt;options xmlns="xdmp:eval"&amp;gt;&amp;lt;
  default-xquery-version&amp;gt;0.9-ml&amp;lt;/default-xquery-version&amp;gt;&amp;lt;root
  &amp;gt;c:/...&amp;lt;/options&amp;gt;)&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Analyzing path for search: fn:doc()&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Step 1 is searchable: fn:doc()&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Path is fully searchable.&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Gathering constraints.&lt;/qry:info-trace&gt;
  &lt;qry:word-trace text="cat"&gt;
    &lt;qry:key&gt;12545744176132597186&lt;/qry:key&gt;
  &lt;/qry:word-trace&gt;
  &lt;qry:info-trace&gt;Search query contributed 1 constraint:
  cts:word-query("cat", ("lang=en"), 1)&lt;/qry:info-trace&gt;
  &lt;qry:partial-plan&gt;
    &lt;qry:term-query weight="1"&gt;
      &lt;qry:key&gt;12545744176132597186&lt;/qry:key&gt;
    &lt;/qry:term-query&gt;
  &lt;/qry:partial-plan&gt;
  &lt;qry:info-trace&gt;Executing search.&lt;/qry:info-trace&gt;
  &lt;qry:final-plan&gt;
    &lt;qry:and-query&gt;
      &lt;qry:term-query weight="1"&gt;
	&lt;qry:key&gt;12545744176132597186&lt;/qry:key&gt;
      &lt;/qry:term-query&gt;
    &lt;/qry:and-query&gt;
  &lt;/qry:final-plan&gt;
  &lt;qry:info-trace&gt;Selected 2 fragments to filter&lt;/qry:info-trace&gt;
  &lt;qry:result estimate="2"/&gt;
&lt;/qry:query-plan&gt;

</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml" ;

xdmp:plan(
 cts:search(/document, 
   cts:word-query("cut?", 
    ("unstemmed", "wildcarded") ) ) ) 
(:
The &lt;qry:expansion-trace&gt; element indicates that a 
lexicon expansion occurred on the wildcarded query
(word searches, three character searches and 
a codepoint lexicon are enabled in the database 
configuration for wildcard queries).  The 
&lt;qry:expansion&gt; element shows what term(s) the 
lexicon expansion found.  In this case, "cut?" 
expands to "cute".
:)
=&gt;
&lt;qry:query-plan xmlns:qry="http://marklogic.com/cts/query"&gt;
  &lt;qry:info-trace&gt;xdmp:eval("xquery version &amp;amp;quot;1.0-ml&amp;amp;quot; ;
  &amp;amp;#13;&amp;amp;#10;&amp;amp;#13;&amp;amp;#10;xdmp:plan...", (), 
  &amp;lt;options xmlns="xdmp:eval"&amp;gt;&amp;lt;database&amp;gt;
  13960881382049922482&amp;lt;/database&amp;gt;&amp;lt;default-xquery-version...
  &amp;lt;/options&amp;gt;)&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Analyzing path for search: fn:collection()/document
  &lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Step 1 is searchable: fn:collection()&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Step 2 is searchable: document&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Path is fully searchable.&lt;/qry:info-trace&gt;
  &lt;qry:info-trace&gt;Gathering constraints.&lt;/qry:info-trace&gt;
  &lt;qry:expansion-trace text="cut?"&gt;
    &lt;qry:expansion text="cute"/&gt;
  &lt;/qry:expansion-trace&gt;
  &lt;qry:word-trace text="cute"&gt;
    &lt;qry:key&gt;16588943567160478160&lt;/qry:key&gt;
  &lt;/qry:word-trace&gt;
  &lt;qry:info-trace&gt;Search query contributed 1 constraint: 
  cts:word-query("cut?", ("unstemmed","wildcarded","lang=en"), 1)
  &lt;/qry:info-trace&gt;
  &lt;qry:partial-plan&gt;
    &lt;qry:term-query weight="1"&gt;
      &lt;qry:key&gt;16588943567160478160&lt;/qry:key&gt;
    &lt;/qry:term-query&gt;
  &lt;/qry:partial-plan&gt;
  &lt;qry:info-trace&gt;Executing search.&lt;/qry:info-trace&gt;
  &lt;qry:final-plan&gt;
    &lt;qry:and-query&gt;
      &lt;qry:or-two-queries&gt;
	&lt;qry:term-query weight="0"&gt;
	  &lt;qry:key&gt;3998944933214536873&lt;/qry:key&gt;
	&lt;/qry:term-query&gt;
	&lt;qry:term-query weight="0"&gt;
	  &lt;qry:key&gt;13616698357625443361&lt;/qry:key&gt;
	&lt;/qry:term-query&gt;
      &lt;/qry:or-two-queries&gt;
      &lt;qry:term-query weight="1"&gt;
	&lt;qry:key&gt;16588943567160478160&lt;/qry:key&gt;
      &lt;/qry:term-query&gt;
    &lt;/qry:and-query&gt;
  &lt;/qry:final-plan&gt;
  &lt;qry:info-trace&gt;Selected 1 fragment to filter&lt;/qry:info-trace&gt;
  &lt;qry:result estimate="1"/&gt;
&lt;/qry:query-plan&gt;

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="version" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the current MarkLogic Server version.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:version()
   =&gt; "4.2-1"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="xquery-version" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the XQuery language version of the calling module.
  Currently supported XQuery versions are:
  <ul xmlns="http://www.w3.org/1999/xhtml">
	<li>"0.9-ml": The legacy MarkLogic 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 MarkLogic extensions
    </li>
	<li>"1.0-ml": XQuery version 1.0, with MarkLogic extensions.  This
    is the preferred version of XQuery beginning with release 4.0.
    </li>
	<li>"1.0": Strict XQuery version 1.0.  This XQuery version complies
    as closely as possible with the published XQuery 1.0 specification.
    </li>
      </ul>
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:xquery-version()
   =&gt; "1.0-ml"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="platform" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the operating-system platform upon which MarkLogic Server is running 
  ("solaris", "winnt", "linux", or "macosx").
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:platform()
   =&gt; "winnt"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="architecture" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the hardware architecture upon which MarkLogic Server is running.
  If <code xmlns="http://www.w3.org/1999/xhtml">xdmp:platform()</code> returns "linux",
  it will return "x86_64" or "i686.
  If <code xmlns="http://www.w3.org/1999/xhtml">xdmp:platform()</code> returns "solaris",
  it will return "amd64" or "sparcv9".
  If <code xmlns="http://www.w3.org/1999/xhtml">xdmp:platform()</code> returns "winnt", 
  it will return "amd64" or "i686".  
  If <code xmlns="http://www.w3.org/1999/xhtml">xdmp:platform()</code> returns "macosx", 
  it will return "x86_64".  
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:architecture()
   =&gt; "amd64"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="path" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a string whose value corresponds to the 
  path of the node.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="node" type="node()" optional="false">
    The node whose path is returned.
  </apidoc:param>
      <apidoc:param name="include-document" type="xs:boolean?" optional="true">
    If true, then the path is presented with a leading <code xmlns="http://www.w3.org/1999/xhtml">doc(..)/..</code>,
    otherwise the path is presented as <code xmlns="http://www.w3.org/1999/xhtml">/..</code>.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $arg := &lt;a&gt;&lt;b&gt;&lt;c&gt;ccc&lt;/c&gt;&lt;/b&gt;
                &lt;b&gt;bbb&lt;/b&gt;&lt;/a&gt;
  return xdmp:path($arg/b[1]/c)
  =&gt; "/a/b[1]/c"</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="describe" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a string representing the 
  description of a given item sequence.  If you take
  the output of the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:describe</code> function and evaluate 
  it as an XQuery program, it returns the item(s) input to the
  function.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="item" type="item()*" optional="false">
    The item sequence whose description is returned.
  </apidoc:param>
      <apidoc:param name="maxSequenceLength" type="xs:unsignedInt?" optional="true">
    Represents the maximum number of items per sequence to print.  
    The default is 3.  () means no maximum.
  </apidoc:param>
      <apidoc:param name="maxItemLength" type="xs:unsignedInt*" optional="true">
    Represents the maximum number of characters per item to print.  
    The default is 64.  The minimum is 8.  () means no limit.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">If you specify an item that is in a database, <code>xdmp:describe</code>
  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 
  <code>maxItemLength</code> parameter.
  </p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:describe(current-date())

  =&gt; xs:date("2007-01-15-08:00")</pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $x := &lt;mynode&gt;Some text here.&lt;/mynode&gt;
  return
  xdmp:describe($x)

  =&gt; &lt;mynode&gt;Some text here.&lt;/mynode&gt;</pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  (:  assume mydoc.xml is an XML document with
      the following content:
      &lt;mynode&gt;Some text here.&lt;/mynode&gt; :)
  xdmp:describe(doc("mydoc.xml")/mynode)

  =&gt; doc("mydoc.xml")/mynode</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="hash32" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the 32-bit hash of a string.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="string" type="xs:string" optional="false">
    The string to be hashed.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedInt</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:hash32("/a/b[1]/c")
  =&gt; 152930691</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="hash64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the 64-bit hash of a string.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="string" type="xs:string" optional="false">
    The string to be hashed.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:hash64("/a/b[1]/c")
  =&gt; 5082244643751628547</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="step64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Combines an initial hash with a subsequent hash.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="initial" type="xs:unsignedLong" optional="false">
    An initial hash.
  </apidoc:param>
      <apidoc:param name="step" type="xs:unsignedLong" optional="false">
    A step hash to be combined with the initial hash.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:step64(xdmp:hash64("initial"), xdmp:hash64("step"))
  =&gt; 12899951685816192752</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="add64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Add two 64-bit integer values, discarding overflow. 
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The first value.
  </apidoc:param>
      <apidoc:param name="y" type="xs:unsignedLong" optional="false">
    The second value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:add64(11442580934957149475,14565934789622151058)
  =&gt; 7561771650869748917</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="and64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  AND two 64-bit integer values.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The first value.
  </apidoc:param>
      <apidoc:param name="y" type="xs:unsignedLong" optional="false">
    The second value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:and64(255, 2)
   =&gt; 2
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="mul64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Muliply two 64-bit integer values, discarding overflow. 
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The first value.
  </apidoc:param>
      <apidoc:param name="y" type="xs:unsignedLong" optional="false">
    The second value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:mul64(15107650474313474666,13290239292956375463)
  =&gt; 1404109880107289894</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="not64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  NOT a 64-bit integer value.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The input value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:not64(255)
   =&gt; 18446744073709551360
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="or64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  OR two 64-bit integer values.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The first value.
  </apidoc:param>
      <apidoc:param name="y" type="xs:unsignedLong" optional="false">
    The second value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:or64(255, 2)
   =&gt; 255
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="xor64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  XOR two 64-bit integer values.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The first value.
  </apidoc:param>
      <apidoc:param name="y" type="xs:unsignedLong" optional="false">
    The second value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:xor64(255, 2)
   =&gt; 253
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="lshift64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Left-shift a 64-bit integer value.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The value to shift.
  </apidoc:param>
      <apidoc:param name="y" type="xs:integer" optional="false">
    The left shift to perform. This value may be negative.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:lshift64(255, 2)
   =&gt; 1020
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="rshift64" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Right-shift a 64-bit integer value.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="x" type="xs:unsignedLong" optional="false">
    The value to shift.
  </apidoc:param>
      <apidoc:param name="y" type="xs:integer" optional="false">
    The right shift to perform. This value may be negative.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:rshift64(255, 2)
   =&gt; 63
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="random" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a random unsigned integer between 0 and a number up to 64 bits long.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="max" type="xs:unsignedLong" optional="true">
    The optional maximum value (inclusive).  
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:random(100)
  =&gt; 47</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="hex-to-integer" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Parses a hexadecimal string, returning an integer.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="hex" type="xs:string" optional="false">
    The hexadecimal string.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:integer</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:hex-to-integer("1234567890abcdef")
   =&gt; 1311768467294899695
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="integer-to-hex" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a hexadecimal representation of an integer.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="val" type="xs:integer" optional="false">
    The integer value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:integer-to-hex(1234567890)
   =&gt; "499602d2"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="octal-to-integer" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Parses an octal string, returning an integer.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="octal" type="xs:string" optional="false">
    The octal string.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:integer</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:octal-to-integer("12345670")
   =&gt; 2739128
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="integer-to-octal" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns an octal representation of an integer.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="val" type="xs:integer" optional="false">
    The integer value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:integer-to-octal(1234567890)
   =&gt; "11145401322"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="request-timestamp" type="builtin" lib="xdmp" category="Extension" subcategory="Search" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong?</apidoc:return>
    <apidoc:usage>
  The <code xmlns="http://www.w3.org/1999/xhtml">xdmp:request-timestamp</code> 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
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> to evaluate a separate query statement that 
  returns the system timestamp at the time the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> 
  query is evaluated.
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:request-timestamp()
   =&gt; 1234567
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="eval" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the result of evaluating a string
  as an XQuery module.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="xquery" type="xs:string" optional="false">
    The XQuery string to be evaluated.  If the XQuery string contains
    double quotes ("), surround the string with single quotes (').
  </apidoc:param>
      <apidoc:param name="vars" type="item()*" optional="true">
    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.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node. The default value is ().  
    The node for the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> options must be in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> namespace. The following is a sample options
    node:
    <pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
    &lt;options xmlns="xdmp:eval"&gt;
      &lt;isolation&gt;different-transaction&lt;/isolation&gt;
      &lt;prevent-deadlocks&gt;true&lt;/prevent-deadlocks&gt;
    &lt;/options&gt; </pre> 
    <p xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp:eval</code> options include:</p> 
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt><p>&lt;database&gt;</p></dt>
    <dd>The database ID, from <code>xdmp:database("db_name")</code>, 
    <code>xdmp:security-database()</code>, 
    or <code>xdmp:schema-database()</code>. To specify a database other
    than the context database, the 
    <code>http://marklogic.com/xdmp/privileges/xdmp-eval-in</code> privilege
    is required.</dd>
    <dt><p>&lt;modules&gt;</p></dt>
    <dd>The modules database ID for processing module imports.
        Specifying no <code>&lt;modules&gt;</code> element in the 
	options node specifies the current modules database. Specifying 
	<code>0</code> specifies using the file system to process 
	module imports. You must have the 
  <code>http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change</code>
  (for <code>xdmp:eval</code>),
  <code>http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change</code>
  (for <code>xdmp:invoke</code>), or the
  <code>http://marklogic.com/xdmp/privileges/xdmp-spawn-modules-change</code>
  (for <code>xdmp:spawn</code>)
        privilege to change either the modules database to another database
       	or to change the root to another path.  You must have the
<code>http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file</code>
  (for <code>xdmp:eval</code>),
<code>http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change-file</code>
  (for <code>xdmp:invoke</code>), or the
<code>http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file</code>
  (for <code>xdmp:spawn</code>)
        privilege to change the modules database to the file 
	system or to change a root on the filesystem.
  </dd>
    <dt><p>&lt;root&gt;</p></dt>
    <dd>The root path for modules.   
        Specifying no <code>&lt;root&gt;</code> element in the options 
	node specifies the current root.  You need the same privileges
	to modify the root as you need to change the <code>module</code>
	option.</dd>
    <dt><p>&lt;timestamp&gt;</p></dt>
    <dd>The system timestamp to use for this evaluation.  Specifying
        no <code>&lt;timestamp&gt;</code> 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 <code>xdmp:request-timestamp()</code>). Specifying
	a timestamp requires the <code>xdmp:timestamp</code> execute 
	privilege.</dd>
    <dt><p>&lt;isolation&gt;</p></dt>
    <dd>(Only valid with <code>xdmp:eval</code> or <code>xdmp:invoke</code>; 
    does not apply to <code>xdmp:spawn</code>.)  Either 
    <code>same-statement</code> or 
    <code>different-transaction</code>. When set to 
    <code>same-statement</code>, 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 <code>same-statement</code>
    isolation with update statements; query statements with 
    <code>same-statement</code> isolation will throw an exception.  When set to 
    <code>different-transaction</code>, 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 <code>different-transaction</code> 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 
    <code>isolation</code> option set to <code>same-statement</code>.
    The default value for the <code>isolation</code> option
    is <code>different-transaction</code>. For more details, see the 
    "Understanding Transactions in MarkLogic Server" chapter of the 
    <a href="http://developer.marklogic.com/pubs">Developer's Guide</a>.
    </dd>
    <dt><p>&lt;prevent-deadlocks&gt;</p></dt>
    <dd>(Only valid with <code>xdmp:eval</code> or <code>xdmp:invoke</code>; 
    does not apply to <code>xdmp:spawn</code>.) 
    Specify <code>true</code> for the server to disallow update requests
    from an update transaction.  Only has an effect when the 
    <code>isolation</code> option is set to <code>different-transaction</code>
    as there is no possibility of a deadlock if the <code>isolation</code> 
    option is set to <code>same-statement</code>. 
    When set to <code>true</code> in an update request calling another
    update request, MarkLogic Server throws the 
    <code>XDMP-PREVENTDEADLOCKS</code>
    exception.  Setting this option to <code>true</code> prevents 
    the possibility of deadlocks occurring when running eval/invoke of 
    an update transaction from another update transaction. The default value 
    for the <code>prevent-deadlocks</code> option is <code>false</code>.
    </dd>
    <dt><p>&lt;default-xquery-version&gt;</p></dt>
    <dd>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:
      <ul>
		<li><code>xdmp:eval</code>: 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.
        </li>
		<li>
        <code>xdmp:invoke</code>: 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
        <code>xdmp:invoke</code>.
        </li>
		<li>
        <code>xdmp:spawn</code>: The XQuery version default set on the
        app server that called <code>xdmp:spawn</code>.  The Task Server
        has no default XQuery version, the version to use is passed as a
        part of the task request.
        </li>
	      </ul>
    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 <code>xdmp:eval</code>
    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
    <code>xdmp:xquery-version</code>.
    </dd>
    <dt><p>&lt;time-limit&gt;</p></dt>
    <dd>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 <code>xdmp:spawn</code>, not to
    <code>xdmp:invoke</code> or <code>xdmp:eval</code>.</dd>
    <dt><p>&lt;user-id&gt;</p></dt>
    <dd>Specifies the user ID for the user to run the request being
    evaluated (the request specified in the <code>$xquery</code> parameter).  
    If no <code>user-id</code> is specified, then the 
    request is run as the current user.  You need to have the 
    <code>xdmp:login</code> 
    (<code>http://marklogic.com/xdmp/privileges/xdmp-login</code>)
    privilege to use the <code>user-id</code> 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 <a href="#eval-ex4">fourth example</a> below.</dd>
    <dt><p>&lt;default-collation&gt;</p></dt>
    <dd>Specifies the collation to use for this context, unless a collation is
    explicitly specified in the XQuery prolog or in a function call that 
    allows you to specify a collation.
    </dd>
    </dl></blockquote>
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:privilege>
<p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xdmp-eval</code></p>
<p xmlns="http://www.w3.org/1999/xhtml">You must have the 
<code>http://marklogic.com/xdmp/privileges/xdmp-eval-in</code> privilege to
specify the <code>&lt;database&gt;</code> option with a database other than the context database.</p>
<p xmlns="http://www.w3.org/1999/xhtml">You must have the 
  <code>http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change</code>
  (for <code>xdmp:eval</code>),
  <code>http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change</code>
  (for <code>xdmp:invoke</code>), or the
  <code>http://marklogic.com/xdmp/privileges/xdmp-spawn-modules-change</code>
  (for <code>xdmp:spawn</code>)
        privilege to change either the modules database to another database
       	or to change the root to another path.  You must have the
<code>http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file</code>
  (for <code>xdmp:eval</code>),
<code>http://marklogic.com/xdmp/privileges/xdmp-invoke-modules-change-file</code>
  (for <code>xdmp:invoke</code>), or the
<code>http://marklogic.com/xdmp/privileges/xdmp-eval-modules-change-file</code>
  (for <code>xdmp:spawn</code>)
        privilege to change the modules database to the file 
	system or to change a root on the filesystem.</p>
	<p xmlns="http://www.w3.org/1999/xhtml">You must have the 
	<code>http://marklogic.com/xdmp/privileges/xdmp-login</code>
	privilege to use the <code>user-login</code> option. </p>
</apidoc:privilege>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:eval("1+1")
  =&gt; 2</pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
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"))

=&gt; hello world
  </pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:eval("doc('/docs/mydoc.xml')",  (),
		  &lt;options xmlns="xdmp:eval"&gt;
		    &lt;database&gt;{xdmp:database("otherdb")}&lt;/database&gt;
		  &lt;/options&gt;)
  =&gt; The '/docs/mydoc.xml' document from the
     otherdb database.</pre>
</apidoc:example>
    <apidoc:example><a id="eval-ex4" xmlns="http://www.w3.org/1999/xhtml"></a><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:eval('xdmp:get-current-user()', (), 
 &lt;options xmlns="xdmp:eval"&gt;
  &lt;user-id&gt;{xdmp:user("someuser")}&lt;/user-id&gt;
 &lt;/options&gt;)
(:
  returns "someuser", assuming "someuser" exists in the
  security database and the user running the eval request has the 
  xdmp:login privilege.
:)
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="eval-in" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  [DEPRECATED: use <a href="#xdmp:eval" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:eval</code></a> with the 
  database option instead] Returns the result of evaluating a string as 
  an XQuery module in a given database.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="xquery" type="xs:string" optional="false">
    The XQuery string to be evaluated.  If the XQuery string contains
    double quotes ("), surround the string with single quotes (').
  </apidoc:param>
      <apidoc:param name="ID" type="xs:unsignedLong" optional="false">
    The database ID, from <code xmlns="http://www.w3.org/1999/xhtml">xdmp:database("db_name")</code>, 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:security-database()</code>, 
    or <code xmlns="http://www.w3.org/1999/xhtml">xdmp:schema-database()</code>.
  </apidoc:param>
      <apidoc:param name="vars" type="item()*" optional="true">
    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.
  </apidoc:param>
      <apidoc:param name="modules" type="xs:unsignedLong?" optional="true">
    The modules database for processing module imports.
    The empty sequence specifies the current modules database.
  </apidoc:param>
      <apidoc:param name="root" type="xs:string?" optional="true">
    The root path for modules.   
    The empty sequence specifies the current root.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:eval-in("1+1",2348790529)
  =&gt; 2</pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
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"))

=&gt; hello world
  </pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="invoke" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the result of evaluating a module at the given path.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="path" type="xs:string" optional="false">
    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 
    <em xmlns="http://www.w3.org/1999/xhtml">Application Developer's Guide</em>. 
  </apidoc:param>
      <apidoc:param name="vars" type="item()*" optional="true">
    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.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
  The options node. The default value is (). The node must be in the 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> namespace.  See the 
  <a href="#xdmp:eval" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:eval</code></a> section for a list of options.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:privilege>
<p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xdmp-invoke</code></p>
</apidoc:privilege>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:invoke("http://example.com/modules/foo.xqy")
  =&gt; 2</pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  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"), 
        &lt;options xmlns="xdmp:eval"&gt;
          &lt;modules&gt;{xdmp:modules-database()}&lt;/modules&gt;
	  &lt;root&gt;http://example.com/application/&lt;/root&gt;
         &lt;/options&gt;)
	 
  =&gt; 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. </pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="invoke-in" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  [DEPRECATED: use <a href="#xdmp:invoke" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:invoke</code></a> with the 
  database option instead] Returns the result of evaluating a module 
  at the given path.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    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).
  </apidoc:param>
      <apidoc:param name="ID" type="xs:unsignedLong" optional="false">
    The database ID, from <code xmlns="http://www.w3.org/1999/xhtml">xdmp:database("db_name")</code>, 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:security-database()</code>, 
    or <code xmlns="http://www.w3.org/1999/xhtml">xdmp:schema-database()</code>.
  </apidoc:param>
      <apidoc:param name="vars" type="item()*" optional="true">
    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.
  </apidoc:param>
      <apidoc:param name="modules" type="xs:unsignedLong?" optional="true">
    The modules database containing the module to invoke.
    The empty sequence specifies the current modules database.
  </apidoc:param>
      <apidoc:param name="root" type="xs:string?" optional="true">
    The root path for modules.   
    The empty sequence specifies the current root.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:invoke-in("http://example.com/modules/foo.xqy",2348790529)
  =&gt; 2</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="security-database" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the database ID of the security database 
  associated with the current database.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:usage>To run queries against the security database, you can specify 
  the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:security-database()</code> function as the second
  parameter to <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval-in()</code>. </apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:security-database()
  =&gt; 8447094497219470018</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="schema-database" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the database ID of the schema database 
  associated with the current database.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:usage>To run queries against the schema database, you can specify 
  the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:schema-database()</code> function as the second
  parameter to <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval-in()</code>. </apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:schema-database()
  =&gt; 15467547981724877000</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="modules-database" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the database ID of the modules database.  Returns 0 if the 
  current App Server uses the file system for its modules.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:modules-database()
  =&gt; 8447094497219470018</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="triggers-database" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the database ID of the triggers database 
  associated with the current database.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:triggers-database()
  =&gt; 8447094497219470018</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="quote" type="builtin" lib="xdmp" category="Extension" subcategory="XML" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the unevaluated serialized representation
  of the input parameter as a string.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="arg" type="item()*" optional="false">
    Input to be quoted.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for this quote operation. The default value is ().  
    The node for the xdmp:quote options must be in the
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:quote</code> namespace. 
    <p xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp:quote</code> options include:</p> 
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt><p>&lt;output-encoding&gt;</p></dt>
    <dd>Specifies the encoding to use for this quote operation. This is
        only used to escape characters that cannot be represented.</dd>
    <dt><p>&lt;output-sgml-character-entities&gt;</p></dt>
    <dd>Specifies if character entities should be output upon serialization
    of the XML.  Valid values are <code>normal</code>, <code>none</code>, 
    <code>math</code>, and <code>pub</code>. 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.</dd>
    <dt><p>&lt;method&gt;</p></dt>
    <dd>Valid values are <code>xml</code>, <code>html</code>, 
    <code>xhtml</code>, and <code>text</code>. This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement. 
    </dd>
    <dt><p>&lt;cdata-section-elements&gt;</p></dt>
    <dd>A list of QNames to output as CDATA sections.   This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;encoding&gt;</p></dt>
    <dd>The encoding. This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;use-character-maps&gt;</p></dt>
    <dd>Valid values are <code>xdmp:sgml-entities-normal</code>, 
    <code>xdmp:sgml-entities-math</code>, 
    and <code>xdmp:sgml-entities-pub</code>. This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;media-type&gt;</p></dt>
    <dd>A mimetype representing a media type. For example,
    <code>text/plain</code> or <code>text/xml</code> (or other valid 
    mimetypes). This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;byte-order-mark&gt;</p></dt>
    <dd>Valid values are <code>yes</code> or <code>no</code>.  This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;indent&gt;</p></dt>
    <dd>Specifies if typed XML (that is, XML for which there is an 
    in-scope schema) should be pretty-printed (indented).  Valid
    values are <code>yes</code> or <code>no</code>.  This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;indent-untyped&gt;</p></dt>
    <dd>Specifies if untyped XML (that is, XML for which there is no 
    in-scope schema) should be pretty-printed (indented).  Valid
    values are <code>yes</code> or <code>no</code>.  This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;include-content-type&gt;</p></dt>
    <dd>Include the content-type declaration when serializing the node.  
    Valid values are 
    <code>yes</code> or <code>no</code>.</dd>
    <dt><p>&lt;escape-uri-attributes&gt;</p></dt>
    <dd>Valid values are <code>yes</code> or <code>no</code>.  
    This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;doctype-public&gt;</p></dt>
    <dd>A public identifier, which is the public identifier to use on the 
    emitted DOCTYPE.  This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;doctype-system&gt;</p></dt>
    <dd>A system identifier, which is the system identifier to use on the 
    emitted DOCTYPE.  This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;omit-xml-declaration&gt;</p></dt>
    <dd>Valid values are <code>yes</code> or <code>no</code>.
    This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;standalone&gt;</p></dt>
    <dd>Valid values are <code>yes</code> or <code>no</code>.
    This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;normalization-form&gt;</p></dt>
    <dd>Valid values are <code>NFC</code>, <code>NFD</code>, 
    and <code>NFKD</code>.  This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    <dt><p>&lt;default-attributes&gt;</p></dt>
    <dd>Specifies whether attributes defaulted with a schema should be
    included in the serialization.
    Valid values are <code>yes</code> or <code>no</code>.
    This is like 
    the corresponding part of both the 
    XSLT <a href="http://www.w3.org/TR/xslt20/#serialization"><code>xsl:output</code></a>
    instruction and the MarkLogic XQuery 
    <code>xdmp:output</code> prolog statement.</dd>
    </dl></blockquote> 
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $arg := &lt;a&gt;aaa&lt;/a&gt;
  return ($arg, xdmp:quote($arg))
  =&gt; (&lt;a&gt;aaa&lt;/a&gt;, "&lt;a&gt;aaa&lt;/a&gt;")</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="unquote" type="builtin" lib="xdmp" category="Extension" subcategory="XML" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Parses a string as XML, returning one or more document nodes.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="arg" type="xs:string" optional="false">
    Input to be unquoted.
  </apidoc:param>
      <apidoc:param name="default-namespace" type="xs:string?" optional="true">
    Default namespace for nodes in the first parameter.
  </apidoc:param>
      <apidoc:param name="options" type="xs:string*" optional="true">
    The options for getting this document.  
    The default value is ().
    <p xmlns="http://www.w3.org/1999/xhtml">Options include:</p>
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt>"repair-full"</dt>
    <dd>Specifies that malformed XML content be repaired.  
        This option has no effect on binary or text documents.</dd>
    <dt>"repair-none"</dt>
    <dd>Specifies that malformed XML content be rejected. 
        This option has no effect on binary or text documents.</dd>
    <dt>"format-text"</dt>
    <dd>Specifies to get the document as a text document, 
        regardless of the URI specified.</dd>
    <dt>"format-binary"</dt>
    <dd>Specifies to get the document as a binary document, 
        regardless of the URI specified.</dd>
    <dt>"format-xml"</dt>
    <dd>Specifies to get the document as an XML document, 
        regardless of the URI specified.</dd>
    <dt>"default-language=<em>xx</em>"</dt>
    <dd> If the root element node specified in the first parameter does not 
    already have an <code>xml:lang</code> attribute, the language to 
    specify in an <code>xml:lang</code> attribute on the root element node. 
    If <code>default-language</code> is not specified, then nothing is 
    added to the root element node. Some examples are 
    <code>default-language=en</code> and <code>default-language=fr</code>.</dd>
    </dl></blockquote>
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()+</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">If no format is specified in $options, it is XML.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">If neither "repair-full" nor "repair-none" is present, 
  the default is specified by the XQuery version of the caller.
  In XQuery version <code>1.0</code> and <code>1.0-ml</code> the default is 
  "repair-none".  In XQuery version <code>0.9-ml</code> the default is 
  "repair-full".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">If $arg is the empty string, <code>xdmp:unquote</code> returns an empty 
  document node.</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:unquote("&lt;foo/&gt;")
  =&gt; &lt;foo/&gt;
  It returns this as a document node.</pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:unquote('&lt;foo&gt;hello&lt;/foo&gt;', "", 
          ("repair-none", "default-language=en"))
  =&gt; &lt;foo xml:lang="en"&gt;hello&lt;/foo&gt;
  It returns this as a document node and does
  not perform tag repair on the node.</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="log" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Logs a debug message to the log file 
  <code xmlns="http://www.w3.org/1999/xhtml">&lt;install_dir&gt;/Logs/ErrorLog.txt</code>.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="msg" type="item()*" optional="false">
    Message for logging.
  </apidoc:param>
      <apidoc:param name="level" type="xs:string?" optional="true">
    One of: emergency, alert, critical, error, warning, notice, info,
      config, debug, fine, finer, or finest. The default level is "info".
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:log("AAAA")
  =&gt; ()</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="log-level" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Retrieves the current server log level.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:log-level()
  =&gt; finest</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="query-meters" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the current value of the resource meters for this 
  query sequence.
</apidoc:summary>
    <apidoc:return>element()</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">The resource meters returned include:</p>
  <blockquote xmlns="http://www.w3.org/1999/xhtml">
  <dl>
  <dt>elapsed-time</dt> 
  <dd>The time elapsed since the start of the processing of this query,
  in the form of a duration.</dd>
  <dt>requests</dt>
  <dd>The number of requests.</dd>
  <dt>list-cache-hits</dt> 
  <dd>The number of successful list cache lookups.  The list
  cache holds search termlists used to accelerate path expressions and
  text searches.</dd>
  <dt>list-cache-misses</dt>
  <dd>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.</dd>
  <dt>in-memory-list-hits</dt>
  <dd>The number of successful list lookups in in-memory
  stands.</dd>
  <dt>expanded-tree-cache-hits</dt>
  <dd>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.</dd>
  <dt>expanded-tree-cache-misses</dt>
  <dd>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.</dd>
  <dt>compressed-tree-cache-hits</dt>
  <dd>The number of successful compressed tree cache lookups.
  The compressed tree cache holds XML document data in the compressed
  representation stored on disk.</dd>
  <dt>compressed-tree-cache-misses</dt>
  <dd>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.</dd>
  <dt>in-memory-compressed-tree-hits</dt>
  <dd>The number of successful compressed tree lookups in
  in-memory stands.</dd>
  <dt>value-cache-hits</dt>
  <dd>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.</dd>
  <dt>value-cache-misses</dt>
  <dd>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.</dd>
  <dt>regexp-cache-hits</dt>
  <dd>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.</dd>
  <dt>regexp-cache-misses</dt>
  <dd>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.</dd>
  <dt>link-cache-hits</dt>
  <dd>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.</dd>
  <dt>link-cache-misses</dt>
  <dd>The number of unsuccessful link cache lookups.  Each
  unsuccessful link cache lookup was followed by a search for the 
  link target tree.</dd>
  <dt>filter-hits</dt>
  <dd>The number of successful search filter matches.</dd>
  <dt>filter-misses</dt>
  <dd>The number of unsuccessful search filter matches.</dd>
  <dt>fragments-added</dt>
  <dd>The number of XML fragments added to the database by an
  update.</dd>
  <dt>fragments-deleted</dt>
  <dd>The number of XML fragments deleted from the database by
  an update.</dd>
  <dt>fs-program-cache-hits</dt>
  <dd>The number of module cache hits from the entire program made from 
  modules on the file system.</dd>
  <dt>fs-program-cache-misses</dt>
  <dd>The number of module cache misses from the entire program made from 
  modules on the file system.</dd>
  <dt>db-program-cache-hits</dt>
  <dd>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).</dd>
  <dt>db-program-cache-misses</dt>
  <dd>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).</dd>
  <dt>env-program-cache-hits</dt>
  <dd>The number of module cache hits from the entire program made from 
  ad hoc XSLT stylesheet nodes.</dd>
  <dt>env-program-cache-misses</dt>
  <dd>The number of module cache misses from the entire program made from 
  ad hoc XSLT stylesheet nodes.</dd>
  <dt>fs-main-module-sequence-cache-hits</dt>
  <dd>The number of main module cache hits from main modules on the 
  file system.</dd>
  <dt>fs-main-module-sequence-cache-misses</dt>
  <dd>The number of main module cache misses from main modules on the 
  file system.</dd>
  <dt>db-main-module-sequence-cache-hits</dt>
  <dd>The number of main module cache hits from main modules in a 
  database.</dd>
  <dt>db-main-module-sequence-cache-misses</dt>
  <dd>The number of main module cache misses from main modules in a 
  database.</dd>
  <dt>fs-library-module-cache-hits</dt>
  <dd>The number of library module cache hits from library modules on the 
  file system.</dd>
  <dt>fs-library-module-cache-misses</dt>
  <dd>The number of library module cache misses from library modules on the 
  file system.</dd>
  <dt>db-library-module-cache-hits</dt>
  <dd>The number of library module cache hits from library modules from the 
  modules database.</dd>
  <dt>db-library-module-cache-misses</dt>
  <dd>The number of library module cache misses from library modules from the 
  modules database.</dd>
  </dl>
  </blockquote>
  <p xmlns="http://www.w3.org/1999/xhtml">Some meters are broken down by fragment root and document URI:</p>
  <blockquote xmlns="http://www.w3.org/1999/xhtml">
  <dl>
  <dt>fragments</dt>
  <dd>A sequence of fragment elements, each containing:
  <dl>
  <dt>root</dt>
  <dd>The fragment root name.</dd>
  <dt>expanded-tree-cache-hits</dt>
  <dd>A count of successful expanded tree cache lookups for this fragment
  root.</dd>
  <dt>expanded-tree-cache-misses</dt>
  <dd>A count of unsuccessful expanded tree cache lookups for this
  fragment root.</dd>
  </dl>
  </dd>
  <dt>documents</dt>
  <dd>A sequence of document elements, each containing:
  <dl>
  <dt>uri</dt>
  <dd>The document URI.</dd>
  <dt>expanded-tree-cache-hits</dt>
  <dd>A count of successful expanded tree cache lookups 
  for this document URI.</dd>
  <dt>expanded-tree-cache-misses</dt>
  <dd>A count of unsuccessful expanded tree cache lookups 
  for this document URI.</dd>
  </dl>
  </dd>
  </dl>
  </blockquote>
  <p xmlns="http://www.w3.org/1999/xhtml">There are also meters that measure the query activity per host. There is
  a <code>qm:hosts</code> element with one <code>qm:host</code> child per 
  host that participates in the query. Each <code>qm:host</code> element 
  contains meters showing the round-trip-time and round-trip-count for 
  communications between the evaluator host and the host referenced in the
  <code>xdmp:query-meters</code> output. The <code>qm:hosts</code> element is
  empty for a single-node cluster.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Certain operations are run concurrently with the timing operations, 
  and if those operations are not actually used in the query, they might not 
  be included in the timings. This occurs for operations like 
  <code>xdmp:estimate</code>, <code>xdmp:exists</code>, and lexicon calls
  (for example, <code>cts:element-values</code>).  If you want to see the 
  total timings that include calls that are not used, you can form some other
  expression with the results of the calls.  For example, if you have an 
  expression that calls <code>xdmp:estimate</code> in a <code>let</code> 
  expression, you can add 0 to the output, which causes it to be included in 
  the timings (something like <code>xdmp:estimate($query) + 0</code>).</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:query-meters();
  =&gt; 
  &lt;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"&gt;
    &lt;qm:elapsed-time&gt;PT0.22S&lt;/qm:elapsed-time&gt;
    &lt;qm:requests&gt;1&lt;/qm:requests&gt;
    &lt;qm:list-cache-hits&gt;0&lt;/qm:list-cache-hits&gt;
    &lt;qm:list-cache-misses&gt;0&lt;/qm:list-cache-misses&gt;
    &lt;qm:in-memory-list-hits&gt;0&lt;/qm:in-memory-list-hits&gt;
    &lt;qm:expanded-tree-cache-hits&gt;0
       &lt;/qm:expanded-tree-cache-hits&gt;
    &lt;qm:expanded-tree-cache-misses&gt;0
       &lt;/qm:expanded-tree-cache-misses&gt;
    &lt;qm:compressed-tree-cache-hits&gt;0
       &lt;/qm:compressed-tree-cache-hits&gt;
    &lt;qm:compressed-tree-cache-misses&gt;0
       &lt;/qm:compressed-tree-cache-misses&gt;
    &lt;qm:in-memory-compressed-tree-hits&gt;0
       &lt;/qm:in-memory-compressed-tree-hits&gt;
    &lt;qm:value-cache-hits&gt;0&lt;/qm:value-cache-hits&gt;
    &lt;qm:value-cache-misses&gt;0&lt;/qm:value-cache-misses&gt;
    &lt;qm:regexp-cache-hits&gt;0&lt;/qm:regexp-cache-hits&gt;
    &lt;qm:regexp-cache-misses&gt;0&lt;/qm:regexp-cache-misses&gt;
    &lt;qm:link-cache-hits&gt;0&lt;/qm:link-cache-hits&gt;
    &lt;qm:link-cache-misses&gt;0&lt;/qm:link-cache-misses&gt;
    &lt;qm:fragments-added&gt;0&lt;/qm:fragments-added&gt;
    &lt;qm:fragments-deleted&gt;0&lt;/qm:fragments-deleted&gt;
    &lt;qm:fs-program-cache-hits&gt;1&lt;/qm:fs-program-cache-hits&gt;
    &lt;qm:fs-program-cache-misses&gt;0&lt;/qm:fs-program-cache-misses&gt;
    &lt;qm:db-program-cache-hits&gt;0&lt;/qm:db-program-cache-hits&gt;
    &lt;qm:db-program-cache-misses&gt;0&lt;/qm:db-program-cache-misses&gt;
    &lt;qm:env-program-cache-hits&gt;0&lt;/qm:env-program-cache-hits&gt;
    &lt;qm:env-program-cache-misses&gt;0&lt;/qm:env-program-cache-misses&gt;
    &lt;qm:fs-main-module-sequence-cache-hits&gt;0
       &lt;/qm:fs-main-module-sequence-cache-hits&gt;
    &lt;qm:fs-main-module-sequence-cache-misses&gt;0
       &lt;/qm:fs-main-module-sequence-cache-misses&gt;
    &lt;qm:db-main-module-sequence-cache-hits&gt;0
       &lt;/qm:db-main-module-sequence-cache-hits&gt;
    &lt;qm:db-main-module-sequence-cache-misses&gt;0
       &lt;/qm:db-main-module-sequence-cache-misses&gt;
    &lt;qm:fs-library-module-cache-hits&gt;0
       &lt;/qm:fs-library-module-cache-hits&gt;
    &lt;qm:fs-library-module-cache-misses&gt;0
       &lt;/qm:fs-library-module-cache-misses&gt;
    &lt;qm:db-library-module-cache-hits&gt;0
       &lt;/qm:db-library-module-cache-hits&gt;
    &lt;qm:db-library-module-cache-misses&gt;0
       &lt;/qm:db-library-module-cache-misses&gt;
    &lt;qm:fragments/&gt;
    &lt;qm:documents/&gt;
    &lt;qm:hosts/&gt;
  &lt;/qm:query-meters&gt; </pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">

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

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

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

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

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="elapsed-time" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the elapsed time since the start of processing of this query.  Gives
  the same information as the <code xmlns="http://www.w3.org/1999/xhtml">elapsed-time</code> element of the 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:query-meters</code> output, but has less overhead than calling
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:query-meters</code>.
</apidoc:summary>
    <apidoc:return>xs:dayTimeDuration</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">Certain operations are run concurrently with the timing operations, 
  and if those operations are not actually used in the query, they might not 
  be included in the timings. This occurs for operations like 
  <code>xdmp:estimate</code>, <code>xdmp:exists</code>, and lexicon calls
  (for example, <code>cts:element-values</code>).  If you want to see the 
  total timings that include calls that are not used, you can form some other
  expression with the results of the calls.  For example, if you have an 
  expression that calls <code>xdmp:estimate</code> in a <code>let</code> 
  expression, you can add 0 to the output, which causes it to be included in 
  the timings (something like <code>xdmp:estimate($query) + 0</code>).</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">

xquery version "1.0-ml";

fn:count(collection()),
xdmp:elapsed-time()

=&gt; The count of the number of documents in the database followed by
   the elapsed-time of the query:

   153
   PT0.04S

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="query-trace" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Enables or disables tracing of this query.
  When query tracing is enabled, "info" level messages
  are logged detailing the search optimizations performed.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="enabled" type="xs:boolean" optional="false">
    Specify true to enable query tracing, false to disenable query tracing.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">Search optimizations are performed in three phases:</p>
  <blockquote xmlns="http://www.w3.org/1999/xhtml">
  <dl>
  <dt>the path analysis phase</dt>
  <dd>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.</dd>
  <dt>the search constraint gathering phase</dt>
  <dd>In this phase, search constraints are gathered from the path 
  expression components. The number of constraints contributed by 
  each path component is logged.</dd>
  <dt>the search execution phase</dt>
  <dd>In this phase, a search is performed using the gathered constraints.
   The actual number of fragments selected for filtering is logged.</dd>
  </dl>
  </blockquote>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:query-trace(true())
  =&gt; ()
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="node-uri" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the document-uri property of the parameter or its ancestor. 
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="node" type="node()" optional="false">
    The node whose URI is returned.
   </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:node-uri(doc("http://marklogic.com/document"))
   =&gt; "http://marklogic.com/document"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="node-database" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the database id where the parameter is stored. If
  the specified node does not come from a document in a database, then
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:node-database</code> returns an empty list.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="node" type="node()" optional="false">
    The node whose database is returned.
   </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:node-database(doc("http://marklogic.com/document"))
   =&gt; 18384173956586417397
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="product-edition" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the current MarkLogic product edition.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:product-edition()
   =&gt; "Standard"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="document-locks" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string*" optional="true">
    A document URI.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:document-locks("example.xml")
=&gt;
&lt;?xml version="1.0" encoding="ASCII"?&gt;
&lt;lock:lock xmlns:lock="http://marklogic.com/xdmp/lock"&gt;
  &lt;lock:lock-type&gt;write&lt;/lock:lock-type&gt;
  &lt;lock:lock-scope&gt;exclusive&lt;/lock:lock-scope&gt;
  &lt;lock:active-locks&gt;
    &lt;lock:active-lock&gt;
      &lt;lock:depth&gt;0&lt;/lock:depth&gt;
      &lt;lock:owner&gt;
        &lt;DAV:href xmlns:DAV="DAV:"&gt;http://example.com/~user&lt;/DAV:href&gt;
      &lt;/lock:owner&gt;
      &lt;lock:timeout&gt;120&lt;/lock:timeout&gt;
      &lt;lock:lock-token&gt;http://marklogic.com/xdmp/locks/1c267a036b8480c3
      &lt;/lock:lock-token&gt;
      &lt;lock:timestamp&gt;1290136652&lt;/lock:timestamp&gt;
      &lt;sec:user-id xmlns:sec="http://marklogic.com/xdmp/security"&gt;
        893641342095093063&lt;/sec:user-id&gt;
    &lt;/lock:active-lock&gt;
  &lt;/lock:active-locks&gt;
&lt;/lock:lock&gt;
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

(: 
   The time is in epoch time, which is seconds from the start 
   of 1970, so this code does a little math on the values in 
   the lock document to figure out how many seconds are left 
   for the lock.  Assumes a lock on /example.xml, for example 
   by running the following:

xquery version "1.0-ml";
declare namespace DAV="DAV:";

xdmp:lock-acquire("/example.xml", 
           "exclusive",
           "0",
           &lt;DAV:href&gt;http://example.com/~user&lt;/DAV:href&gt;,
           xs:unsignedLong(120))
   
:)
let $lock := xdmp:document-locks("/example.xml")
let $lock-duration := 
   $lock/lock:lock/lock:active-locks/lock:active-lock/
         lock:timeout/fn:data(.)
let $current-epoch-time := 
 fn:round(
  ( fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00") )
  div xs:dayTimeDuration('PT1S') ) 
let $start-time := 
  $lock/lock:lock/lock:active-locks/lock:active-lock/
        lock:timestamp/fn:data(.)
let $end-time := $start-time + $lock-duration
let $seconds-left := $end-time - $current-epoch-time
return 
 ($current-epoch-time, $start-time, $seconds-left)
=&gt;
1290136837
1290136832
115
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="document-properties" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string*" optional="true">
    A sequence of document URIs.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-properties("/mydoc.xml")
  =&gt;
&lt;prop:properties xmlns:prop="http://marklogic.com/xdmp/property"&gt;
  &lt;cpf:processing-status xmlns:cpf="http://marklogic.com/cpf"&gt;done
    &lt;/cpf:processing-status&gt;
  &lt;cpf:last-updated xmlns:cpf="http://marklogic.com/cpf"&gt;
    2010-05-24T16:28:11.577608-07:00&lt;/cpf:last-updated&gt;
  &lt;cpf:state xmlns:cpf="http://marklogic.com/cpf"&gt;
    http://marklogic.com/states/final&lt;/cpf:state&gt;
  &lt;prop:last-modified&gt;2010-05-24T16:29:58-07:00&lt;/prop:last-modified&gt;
&lt;/prop:properties&gt;

</pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-properties()
    =&gt; 
    &lt;prop:properties 
          xmlns:prop="http://marklogic.com/xdmp/property"&gt;
    Property Node1
    &lt;/prop:properties&gt;
    &lt;prop:properties 
          xmlns:prop="http://marklogic.com/xdmp/property"&gt;
    Property Node2
    &lt;/prop:properties&gt;
    &lt;prop:properties 
          xmlns:prop="http://marklogic.com/xdmp/property"&gt;
    Property NodeN
    &lt;/prop:properties&gt;
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="document-get-quality" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the quality of the specified document if the document exists.  
  Otherwise, returns the empty sequence.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The URI of the document in question.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:integer?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-get-quality("example.xml")
  =&gt; 10
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="document-forest" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The URI of the document, lock, or property.
  </apidoc:param>
      <apidoc:param name="forest-ids" type="xs:unsignedLong*" optional="true">
    Restricts the ID(s) of the forest(s) in which this function may return.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:integer?</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-forest("example.xml")
  =&gt; 12972338785465832200
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="forest" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the the ID of the forest specified as the parameter.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:string" optional="false">
    The name of the forest.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:forest("myForest")
  =&gt; 15495681647217162987
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="database" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:string" optional="true">
    The name of the database.
    The default value is the name of the current database.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:database("myDB")
  =&gt; 74495681647284736476
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="database-forests" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of forest IDs in the specified database.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="database" type="xs:unsignedLong" optiona="false" optional="false">
    A database ID.
  </apidoc:param>
      <apidoc:param name="include-replicas" type="xs:boolean?" optional="true">
    True if replica forest ids should also be included.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:database-forests(xdmp:database("Documents"))
  =&gt; (8456374036761185098, 10615125154705099114)
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="forest-open-replica" type="builtin" lib="xdmp" category="AdminBuiltins" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a forest id or its open replica id if it is currently experiencing
  a local disk failover.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="forestIDs" type="unsignedLong*" optional="false">
    The IDs of the forests that may have failed over.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:forest-open-replica(xdmp:database-forests("Documents"))
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="database-name" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Return the name of the database with the given ID.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="id" type="xs:unsignedLong" optional="false">
    A database ID.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:database-name(8456374036761185098)
=&gt; "Documents"
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="server-name" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Return the name of the App Server with the given ID.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="id" type="xs:unsignedLong" optional="false">
    A App Server ID.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:server-name(845637403676198)
=&gt; "Docs"
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="forest-name" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Return the name of the forest with the given id.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="id" type="xs:unsignedLong" optional="false">
    A forest ID.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:forest-name(8456374036761185098)
=&gt; "Documents"
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="databases" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of the IDs of all the databases in the system.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:databases()
   =&gt; (14389140626518478220,
          8456374036761185098,
	  10615125154705099114)
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="forests" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of the IDs of all the forests in the system.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:forests()
   =&gt; 18263538320779601865
2760886727871312968
1551965607977434000
2714941248661564752
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="forest-databases" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the database ID corresponding to the database to which 
  the specified forest belongs.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="forest" type="xs:unsignedLong" optional="false">
    A forest ID.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:forest-databases(xdmp:forest("Documents"))
  =&gt; 2032458498523149048
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="document-get" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the document in the file specified by $location.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="location" type="xs:string" optional="false">
    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. If the scheme is file (that is, if the string starts
    with "file://"), then the document is requested over file protocol from
    the local filesystem.
    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. 
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for getting this document. The default value is ().  
    The node for the xdmp:document-get options must be in the
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:document-get</code> namespace. This parameter can also include
    option elements in the <a href="#xdmp:http-get" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:http</code></a>
    namespace for the HTTP parameters.  
    <p xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp:document-get</code> options include:</p> 
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt><p>&lt;default-namespace&gt;</p></dt>
    <dd>The namespace to use if there is no namespace at the root node of
    the document. The default value is "".</dd>
    <dt><p>&lt;repair&gt;</p></dt>
    <dd>A value of <code>full</code> specifies that malformed XML content be 
        repaired.  A value of <code>none</code> 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 <code>1.0</code> and <code>1.0-ml</code> the default 
	is <code>none</code>.  In XQuery <code>0.9-ml</code> the 
	default is <code>full</code>.
        This option has no effect on binary or text documents.</dd>
    <dt><p>&lt;format&gt;</p></dt>
    <dd>A value of <code>text</code> specifies to get the document as a 
        text document, regardless of the URI specified. A value of 
	<code>binary</code> specifies to get the document as a binary 
	document, regardless of the URI specified. A value of <code>xml</code>
       	specifies to get the document as an XML document, regardless of the 
	URI specified.</dd>
    <dt><p>&lt;default-language&gt;</p></dt>
    <dd>The language to specify in an <code>xml:lang</code> attribute on the
    root element node if the root element node does not already have an 
    <code>xml:lang</code> attribute. If <code>default-language</code> is
    not specified, then nothing is added to the root element node.</dd>
    <dt><p>&lt;encoding&gt;</p></dt>
    <dd>Specifies the encoding to use when reading the document into MarkLogic
    Server.  Supported values include <code>UTF-8</code>, 
    <code>ISO-8859-1</code>, as well as many other popular encodings.  
    See the <em>Search Developer's Guide</em> 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 
    <code>encoding</code> option will be matched to an encoding name according
    to the Unicode Charset Alias Matching rules 
    (<a href="http://www.unicode.org/reports/tr22/#Charset_Alias_Matching">http://www.unicode.org/reports/tr22/#Charset_Alias_Matching</a>). 
    An automatic encoding detector will be used if the value <code>auto</code>
    is specified.
    If no encoding can be detected, the encoding defaults to UTF-8.
    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, <code>xdmp:http-get</code>), otherwise it defaults
    to UTF-8; any encoding http headers are ignored if there is any
    value specified for the <code>encoding</code> option.</dd>
    </dl></blockquote>
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>node()</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">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.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">If no <code>repair</code> option is specified, 
  the default is specified by the XQuery version of the caller.
  In XQuery version <code>1.0</code> and <code>1.0-ml</code> the default is 
  <code>&lt;repair&gt;none&lt;/repair&gt;</code>.  In XQuery version 
  <code>0.9-ml</code> the default is 
  <code>&lt;repair&gt;full&lt;/repair&gt;</code>.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">When the document is from an HTTP server, 
  <code>xdmp:document-get</code> 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 <a href="#xdmp:http-get"><code>xdmp:http-get</code></a> instead, which
  returns both the response header and the response.</p>
</apidoc:usage>
    <apidoc:privilege>
   <code xmlns="http://www.w3.org/1999/xhtml">http://marklogic.com/xdmp/privileges/xdmp-document-get</code>
</apidoc:privilege>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-get("myDocument.xml")
  =&gt; the xml contained in myDocument.xml, 
        for example, &lt;myDocument/&gt;
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-get("myDocument.html", 
       &lt;options xmlns="xdmp:document-get"&gt;
           &lt;repair&gt;full&lt;/repair&gt;
       &lt;/options&gt;)
  =&gt; myDocument.html as an XML document that has gone 
     through any needed tag repair
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-get("http://myCompany.com/file.xml", 
       &lt;options xmlns="xdmp:document-get"
                xmlns:http="xdmp:http"&gt;
           &lt;format&gt;xml&lt;/format&gt;
           &lt;http:authentication&gt;
	      &lt;http:username&gt;user&lt;/http:username&gt;
	      &lt;http:password&gt;pass&lt;/http:password&gt;
	   &lt;/http:authentication&gt;
       &lt;/options&gt;)
  =&gt; gets an XML document named file.xml, sending the 
     authentication credentials user/pass to the 
     http://myCompany.com server
  
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="get" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  [DEPRECATED: use <a href="#xdmp:document-get" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:document-get</code></a>
  instead] Returns the document in the XML file specified by $path.
  <p xmlns="http://www.w3.org/1999/xhtml">This function is deprecated and will be removed from a future release. 
  Use <a href="#xdmp:document-get"><code>xdmp:document-get</code></a> instead.</p>
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="path" type="xs:string" optional="false">
    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.
  </apidoc:param>
      <apidoc:param name="default-namespace" type="xs:string?" optional="true">
    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 "".
  </apidoc:param>
      <apidoc:param name="options" type="xs:string*" optional="true">
    The options for getting this document.  
    The default value is ().
    <p xmlns="http://www.w3.org/1999/xhtml">Options include:</p>
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt>"repair-full"</dt>
    <dd>Specifies that malformed XML content be repaired.  
        This option has no effect on binary or text documents.</dd>
    <dt>"repair-none"</dt>
    <dd>Specifies that malformed XML content be rejected. 
        This option has no effect on binary or text documents.</dd>
    <dt>"format-text"</dt>
    <dd>Specifies to get the document as a text document, 
        regardless of the URI specified.</dd>
    <dt>"format-binary"</dt>
    <dd>Specifies to get the document as a binary document, 
        regardless of the URI specified.</dd>
    <dt>"format-xml"</dt>
    <dd>Specifies to get the document as an XML document, 
        regardless of the URI specified.</dd>
    <dt>"lang=en"</dt>
    <dd>Specifies that the document is in english.</dd>
    </dl></blockquote>
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>node()</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">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.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">If neither "repair-full" nor "repair-none" is present, 
  the default is specified by the XQuery version of the caller.
  In XQuery version <code>1.0</code> and <code>1.0-ml</code> the default is 
  "repair-none".  In XQuery version <code>0.9-ml</code> the default is 
  "repair-full".</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:get("foo.xml")
  =&gt; &lt;foo/&gt;
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:get("foo.html", "", ("repair-full", "format-xml"))
  =&gt; foo.html as an XML document that has gone through any 
        needed tag repair
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="directory" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the documents in a directory.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string*" optional="false">
    The URI of the directory.  Typically, directory URIs end with a forward
    slash (/).
  </apidoc:param>
      <apidoc:param name="depth" type="xs:string?" optional="true">
    "1" for immediate children, "infinity" for all. 
    If not supplied, depth is "1".
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  for $d in xdmp:directory("http://example.com/foo/","1")
  return xdmp:node-uri($d)
  =&gt; http://example.com/foo/bar.xml 
     http://example.com/foo/baz.xml
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="directory-properties" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of properties documents, one for each document in 
  the specified directory that has a corresponding properties document.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The URI of the directory.  Typically, directory URIs end with a forward
    slash (/).
  </apidoc:param>
      <apidoc:param name="depth" type="xs:string?" optional="true">
    "1" for immediate children, "infinity" for all children. 
    If not supplied, depth is "1".
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:directory-properties("http://example.com/dir/","1")
  =&gt; &lt;prop:properties 
            xmlns:prop="http://marklogic.com/xdmp/property"&gt;
         &lt;prop:directory/&gt;
     &lt;/prop:properties&gt;
   </pre>
   <p xmlns="http://www.w3.org/1999/xhtml">The properties document returned has one directory element, indicating 
   that there is a single directory that is an immediate child of the 
   specified directory.</p>
</apidoc:example>
  </apidoc:function><apidoc:function name="collection-properties" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of properties documents, one for each document in the 
  specified collection(s) that has a corresponding properties document.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string*" optional="true">
    The URI(s) of the collection(s).
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  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)

  =&gt; 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
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="directory-locks" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns locks of documents in a directory.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string*" optional="false">
    The URI of the directory.  Typically, directory URIs end with a forward
    slash (/).
  </apidoc:param>
      <apidoc:param name="depth" type="xs:string?" optional="true">
    "1" for immediate children, "infinity" for all. 
    If not supplied, depth is "1".
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  for $d in xdmp:directory-locks("http://example.com/foo/","1")
  return xdmp:node-uri($d)
  =&gt; http://example.com/foo/bar.xml 
     http://example.com/foo/baz.xml
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="collection-locks" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns locks of documents in a collection.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string*" optional="true">
    The input URI.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  for $d in xdmp:collection-locks(
                     ("http://example.com/col1/",
                      "http://example.com/col2/"))
  return xdmp:node-uri($d)
  =&gt; http://example.com/bar.xml 
     http://example.com/baz.xml
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="uri-content-type" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the content type of the given URI as matched in the mimetypes 
  configuration. xdmp:content-type continues to work too.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The document URI.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:uri-content-type("example.txt")
  =&gt; text/plain
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:uri-content-type("example.xml")
  =&gt; text/xml
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:uri-content-type("example.doc")
  =&gt; application/msword
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="uri-format" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the format of the given URI as matched in the mimetypes 
  configuration. 
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The document URI.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:uri-format("example.txt")
  =&gt; text
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:format("example.xml")
  =&gt; xml
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="document-get-properties" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the property values for a document's property.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The document URI.
  </apidoc:param>
      <apidoc:param name="property" type="xs:QName" optional="false">
    The property name. This is the QName of the top-level property element
    in the specified properties document.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>element()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:document-get-properties(
         "http://example.com/foo.xml",
         fn:QName("http://examples.com/","priority"))
   =&gt; &lt;priority xmlns="http://examples.com/"&gt;5&lt;/priority&gt;
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="access" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns whether a given action on the specified document URI would succeed.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The document URI.
  </apidoc:param>
      <apidoc:param name="action" type="xs:string" optional="false">
    The type of access: "create", "insert", "update", or "execute". 
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:boolean</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:access(
         "http://example.com/foo.xml",
         "create")
   =&gt; true()
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="http-get" type="builtin" lib="xdmp" category="Extension" subcategory="HTTP" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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).
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
   The URI of the requested document.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for this request. The default value is ().  
    The node for the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-get</code> options must be in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http</code> namespace. This parameter can also include 
    certain option elements (for example, <code xmlns="http://www.w3.org/1999/xhtml">repair</code>, 
    <code xmlns="http://www.w3.org/1999/xhtml">encoding</code>, <code xmlns="http://www.w3.org/1999/xhtml">default-language</code>) in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:document-load</code> and <a href="#xdmp:document-get" xmlns="http://www.w3.org/1999/xhtml">
    <code>xdmp:document-get</code></a> 
    namespaces.    
    <p xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp:http-get</code> options include:</p> 
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt><p>&lt;headers&gt;</p></dt>
    <dd>A sequence of &lt;name&gt;value&lt;/name&gt; pairs. The names can be
    anything, but many HTTP servers understand HTTP names such as 
    <code>content-type</code>. These are turned into name:value HTTP 
    headers. An error is raised if the child elements of the
    &lt;headers&gt; option are not of the form
    &lt;name&gt;value&lt;/name&gt;.</dd>
    <dt><p>&lt;authentication&gt;</p></dt>
    <dd>The credentials and the authentication method to use for 
    this request.  This option has child elements for the 
    <code>username</code> and <code>password</code>. 
    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 <code>method</code> attribute on the 
    &lt;authentication&gt; 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.</dd>
    <dt><p>&lt;timeout&gt;</p></dt>
    <dd>The amount of time, in seconds, to wait until the HTTP connection
    times out. The default value is the <code>http timeout</code> for the 
    group.</dd>
    <dt><p>&lt;ciphers&gt;</p></dt>
    <dd>A standard cipher string. For details on legal ciper strings, see 
    <a href="http://www.openssl.org/docs/apps/ciphers.html#CIPHER_STRINGS">http://www.openssl.org/docs/apps/ciphers.html#CIPHER_STRINGS</a>.
    </dd>
    <dt><p>&lt;client-cert&gt;</p></dt>
    <dd>A PEM encoded client certificate for identifying the client to  
    the remote server.</dd>
    <dt><p>&lt;client-key&gt;</p></dt>
    <dd>The private key that corresponds to <code>client-cert</code>.</dd>
    <dt><p>&lt;pass-phrase&gt;</p></dt>
    <dd>A pass phrase, if one is needed to decrypt client-key.</dd>
    <dt><p>&lt;method&gt;</p></dt>
    <dd>The authentication method, which can be either "basic" or "digest".</dd>
    <dt><p>&lt;username&gt;</p></dt>
    <dd>A user name, if required for authentication.</dd>
    <dt><p>&lt;password&gt;</p></dt>
    <dd>A password, if required for authentication.</dd>
    <dt><p>&lt;allow-sslv3&gt;</p></dt>
    <dd>A boolean value to specify whether to communicate using the SSL v3 protocol.
     The default is <code>true</code>, which indicates communication using the 
     SSL v3 protocol.</dd>
    <dt><p>&lt;allow-tls&gt;</p></dt>
    <dd>A boolean value to specify whether to communicate using the TLS protocol.
     The default is <code>true</code>, which indicates communication using the 
     TLS protocol.</dd>
    <dt><p>&lt;verify-cert&gt;</p></dt>
    <dd>A boolean value to specify whether the server's certificate should be
    verified. The default value is <code>true</code>. A value of <code>false</code>
    should only be specfied after careful consideration of the security risks since it
    permits communication with servers whose certificates are expired, revoked,
    or signed by unknown or untrusted authorities. A value of <code>false</code>
    also removes protection against a man-in-the-middle attack.</dd>
    <dt><p>&lt;ssl-session-cache&gt;</p></dt>
    <dd>A boolean value to specify whether ssl session should be cached and
    reused. The default value is <code>true</code>. A value of <code>false</code>
    should only be specfied if ssl session cache causes problem with a url.</dd>
    </dl>
    </blockquote>
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()+</apidoc:return>
    <apidoc:usage>
   <p xmlns="http://www.w3.org/1999/xhtml">The http functions only operate on URIs that use the http or https 
   schemes; specifying a URI that does not begin with <code>http://</code> 
   or <code>https://</code> throws an exception.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If an http function times out, it throws a socket received 
   exception (SVC-SOCRECV).</p>
   <p xmlns="http://www.w3.org/1999/xhtml">An automatic encoding detector will be used if the value <code>auto</code>
   is specified for the <code>encoding</code> option (in the 
   <code>xdmp:document-get</code>
   namespace).  If no option 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.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">The first node in the output of <code>xdmp:http-get</code> is the
   response header from the http server.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">The second node in the output of <code>xdmp:http-get</code> 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 
   <code>text/html</code>, 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 <code>xdmp:unquote</code> call to 
   parse the response as XML.  You could also use the 
   <code>&lt;format&gt;xml&lt;/format&gt;</code> option (in the
   <code>xdmp:document-get</code> 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 <code>xdmp:tidy</code> call, which
   will treat the text as HTML, clean it up, and return an XHTML XML 
   document.</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:http-get("http://www.my.com/document.xhtml",
     &lt;options xmlns="xdmp:http"&gt;
       &lt;authentication method="basic"&gt;
         &lt;username&gt;myname&lt;/username&gt;
         &lt;password&gt;mypassword&lt;/password&gt;
       &lt;/authentication&gt;
     &lt;/options&gt;)
=&gt; the response from the server as well as the specified document


</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:http-get("http://www.my.com/iso8859document.html",
     &lt;options xmlns="xdmp:document-get"&gt;
       &lt;encoding&gt;iso-8859-1&lt;/encoding&gt;
     &lt;/options&gt;)[2]
=&gt; 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.

</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:unquote(
  xdmp:http-get("http://www.my.com/somexml.xml")[2])
=&gt; 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",
	&lt;options xmlns="xdmp:http-get"&gt;
	   &lt;format xmlns="xdmp:document-get"&gt;xml&lt;/format&gt;
	&lt;/options&gt;)[2]

</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:tidy(
  xdmp:http-get("http://www.my.com/somehtml.html")[2])[2]
=&gt; 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

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="http-head" type="builtin" lib="xdmp" category="Extension" subcategory="HTTP" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Sends the http HEAD method to the specified URI. Returns the http response 
  header for the specified URI.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
   The URI of the document whose response header is being requested.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for this request. The default value is ().  
    The node for the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-head</code> options must be in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http</code> namespace. The options are the same as the other
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-*</code> functions, and the options are documented with the 
    <a href="#xdmp:http-get" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:http-get</code></a> $options parameter.  
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()+</apidoc:return>
    <apidoc:usage>
   <p xmlns="http://www.w3.org/1999/xhtml">The http functions only operate on URIs that use the http or https 
   schemes; specifying a URI that does not begin with <code>http://</code> 
   or <code>https://</code> throws an exception.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If an http function times out, it throws a socket received 
   exception (SVC-SOCRECV).</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:http-head("http://www.my.com/document.xhtml",
     &lt;options xmlns="xdmp:http"&gt;
       &lt;authentication method="basic"&gt;
         &lt;username&gt;myname&lt;/username&gt;
         &lt;password&gt;mypassword&lt;/password&gt;
       &lt;/authentication&gt;
     &lt;/options&gt;)
=&gt; the response header from the server


</pre></apidoc:example>
  </apidoc:function><apidoc:function name="http-options" type="builtin" lib="xdmp" category="Extension" subcategory="HTTP" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Sends the http OPTIONS method to the specified URI. Returns the http response 
  for the specified URI.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
   The URI of the document whose options response is being requested.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for this request. The default value is ().  
    The node for the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-options</code> options must be in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http</code> namespace. The options are the same as the other
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-*</code> functions, and the options are documented with the 
    <a href="#xdmp:http-get" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:http-get</code></a> $options parameter. 
    
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()+</apidoc:return>
    <apidoc:usage>
   <p xmlns="http://www.w3.org/1999/xhtml">The http functions only operate on URIs that use the http or https 
   schemes; specifying a URI that does not begin with <code>http://</code> 
   or <code>https://</code> throws an exception.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If an http function times out, it throws a socket received 
   exception (SVC-SOCRECV).</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:http-options("http://localhost:8000/",
     &lt;options xmlns="xdmp:http"&gt;
       &lt;authentication method="digest"&gt;
         &lt;username&gt;myname&lt;/username&gt;
         &lt;password&gt;mypassword&lt;/password&gt;
       &lt;/authentication&gt;
     &lt;/options&gt;)
=&gt; the response from the HTTP server, for example:

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



</pre></apidoc:example>
  </apidoc:function><apidoc:function name="http-delete" type="builtin" lib="xdmp" category="Extension" subcategory="HTTP" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The URI of the document to delete.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for this request. The default value is ().  
    The node for the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-delete</code> options must be in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http</code> namespace. The options are the same as the other
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-*</code> functions, and the options are documented with the 
    <a href="#xdmp:http-get" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:http-get</code></a> $options parameter. 
    
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()+</apidoc:return>
    <apidoc:usage>
   <p xmlns="http://www.w3.org/1999/xhtml">The http functions only operate on URIs that use the http or https 
   schemes; specifying a URI that does not begin with <code>http://</code> 
   or <code>https://</code> throws an exception.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If an http function times out, it throws a socket received 
   exception (SVC-SOCRECV).</p>
   <p xmlns="http://www.w3.org/1999/xhtml">Note the the <code>xdmp:http-delete</code> 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 
   <a href="apidocs.xqy?fname=UpdateBuiltins#xdmp:document-delete">
   <code>xdmp:document-delete</code></a>
   function.</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:http-delete("http://www.my.com/document.xhtml",
     &lt;options xmlns="xdmp:http"&gt;
       &lt;authentication method="basic"&gt;
         &lt;username&gt;myname&lt;/username&gt;
         &lt;password&gt;mypassword&lt;/password&gt;
       &lt;/authentication&gt;
     &lt;/options&gt;)
=&gt; an optional response from the server


</pre></apidoc:example>
  </apidoc:function><apidoc:function name="http-post" type="builtin" lib="xdmp" category="Extension" subcategory="HTTP" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Sends the http POST request to the server.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
  The URI to which the data is to be posted. 
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for this request. The default value is ().  
    The node for the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-post</code> options must be in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http</code> namespace. 
    <p xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp:http-post</code> options include
    the following option (in the <code>xdmp:http</code> namespace), in 
    addition to the options documented with the 
    <a href="#xdmp:http-get"><code>xdmp:http-get</code></a> $options 
    parameter:</p> 
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt><p>&lt;data&gt;</p></dt>
    <dd>This node can contain any string. Anything in the <code>data</code> 
    node is sent as a string in the PUT or POST body. When POSTing to a web 
    service, the data may need to be a SOAP XML structure or binary content.
    The optional third argument can be used to specify non-text data. 
    </dd>
    <dt><p>The other options are the same as the other <code>xdmp:http-*</code> 
    functions, and the options are documented with the 
    <a href="#xdmp:http-get"><code>xdmp:http-get</code></a> $options 
    parameter.</p></dt>

    </dl></blockquote>
  </apidoc:param>
      <apidoc:param name="data" type="node()?" optional="true">
    The data for this request. This takes is an alternative to the
    <code xmlns="http://www.w3.org/1999/xhtml">data</code> option for the second parameter, and allows binary
    content to be specified.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()+</apidoc:return>
    <apidoc:usage>
   <p xmlns="http://www.w3.org/1999/xhtml">The http functions only operate on URIs that use the http or https 
   schemes; specifying a URI that does not begin with <code>http://</code> 
   or <code>https://</code> throws an exception.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If an http function times out, it throws a socket received 
   exception (SVC-SOCRECV).</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If you expect the request body from this http function to be 
   processed by another application (via a web service, for example),
   you should specify a content-type header. If no content-type header is 
   specified, the content type defaults to text/plain.</p> 
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:http-post("http://www.my.com/document.xhtml",
     &lt;options xmlns="xdmp:http"&gt;
       &lt;authentication method="basic"&gt;
         &lt;username&gt;myname&lt;/username&gt;
         &lt;password&gt;mypassword&lt;/password&gt;
       &lt;/authentication&gt;
     &lt;/options&gt;)
=&gt; the response from the server as well as the specified document

</pre></apidoc:example>
    <apidoc:example><a id="http-data-payload" xmlns="http://www.w3.org/1999/xhtml"></a><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
(: Use xdmp:unquote to encode the XML as a string 
   because the &lt;data&gt; options element is a string :)
let $payload := xdmp:quote(
&lt;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'&gt;
 &lt;SOAP-ENV:Body&gt;
   &lt;my:LogOn&gt;
     &lt;my:User&gt;user&lt;/my:User&gt;
     &lt;my:Password&gt;pass&lt;/my:Password&gt; 
     &lt;my:Ticket&gt;abc123&lt;/my:Ticket&gt;
     &lt;my:newData&gt;1234&lt;/my:newData&gt;
   &lt;/my:LogOn&gt;
 &lt;/SOAP-ENV:Body&gt;
&lt;/SOAP-ENV:Envelope&gt;
)
return
xdmp:http-post("http://www.my.com/document.xhtml",
     &lt;options xmlns="xdmp:http"&gt;
       &lt;authentication method="basic"&gt;
         &lt;username&gt;myname&lt;/username&gt;
         &lt;password&gt;mypassword&lt;/password&gt;
       &lt;/authentication&gt;
       &lt;data&gt;{$payload}&lt;/data&gt;
       &lt;headers&gt;
         &lt;content-type&gt;text/xml&lt;/content-type&gt;
       &lt;/headers&gt;
     &lt;/options&gt;)
=&gt; the response from the server as well as the specified document

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="http-put" type="builtin" lib="xdmp" category="Extension" subcategory="HTTP" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="uri" type="xs:string" optional="false">
    The URI to which the data is to be put.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
    The options node for this request. The default value is ().  
    The node for the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http-put</code> options must be in the 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:http</code> namespace. 
    <p xmlns="http://www.w3.org/1999/xhtml">The options include
    the following option (in the <code>xdmp:http</code> namespace), in 
    addition to the options documented with the 
    <a href="#xdmp:http-get"><code>xdmp:http-get</code></a> $options 
    parameter:</p> 
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt><p>&lt;data&gt;</p></dt>
    <dd>This node can contain any string. Anything in the <code>data</code> 
    node is sent as a string in the PUT or POST body. If binary content is to
    be sent, it can be specified as the optional third argument instead.</dd>
    <dt><p>The other options are the same as the other <code>xdmp:http-*</code> 
    functions, and the options are documented with the 
    <a href="#xdmp:http-get"><code>xdmp:http-get</code></a> $options 
    parameter.</p></dt>
    </dl>
    </blockquote>
  </apidoc:param>
      <apidoc:param name="data" type="node()?" optional="true">
    The data for this request. This takes is an alternative to the
    <code xmlns="http://www.w3.org/1999/xhtml">data</code> option for the second parameter, and allows binary
    content to be specified.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()+</apidoc:return>
    <apidoc:usage>
   <p xmlns="http://www.w3.org/1999/xhtml">The http functions only operate on URIs that use the http or https 
   schemes; specifying a URI that does not begin with <code>http://</code> 
   or <code>https://</code> throws an exception.</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If an http function times out, it throws a socket received 
   exception (SVC-SOCRECV).</p>
   <p xmlns="http://www.w3.org/1999/xhtml">If you expect the request body from this http function to be 
   processed by another application (via a web service, for example),
   you should specify a content-type header. If no content-type header is 
   specified, the content type defaults to text/plain.</p> 
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:http-put("http://www.my.com/document.xhtml",
     &lt;options xmlns="xdmp:http"&gt;
       &lt;authentication method="basic"&gt;
         &lt;username&gt;myname&lt;/username&gt;
         &lt;password&gt;mypassword&lt;/password&gt;
       &lt;/authentication&gt;
     &lt;/options&gt;)
=&gt; the response from the HTTP server as well as the specified document



</pre></apidoc:example>
  </apidoc:function><apidoc:function name="rethrow" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Within the catch section of a try-catch expression,
  re-throw the currently caught error.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  try {
    xdmp:document-delete($uri)
  } catch ($ex) {
    (: ignore documents that aren't there :)
    if ($ex/error:code eq 'XDMP-DOCNOTFOUND') then ()
    else xdmp:rethrow()
  }
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="base64-encode" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Converts plaintext into base64-encoded string.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="plaintext" type="xs:string" optional="false">
    Plaintext to be encoded.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:base64-encode("slings and arrows of outrageous fortune")
   =&gt; c2xpbmdzIGFuZCBhcnJvd3Mgb2Ygb3V0cmFnZW91cyBmb3J0dW5l
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="base64-decode" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Converts base64-encoded string to plaintext.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="encoded" type="xs:string" optional="false">
     Encoded text to be decoded.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:base64-decode(
     "c2xpbmdzIGFuZCBhcnJvd3Mgb2Ygb3V0cmFnZW91cyBmb3J0dW5l")
=&gt; slings and arrows of outrageous fortune
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="subbinary" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a binary node made up of a subset of the given binary node.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="source" type="binary()" optional="false">
    A binary node whose subset will be returned
  </apidoc:param>
      <apidoc:param name="starting-location" type="xs:double" optional="false">
    The new binary node starts at the byte position indicated by starting-location.
    The first byte is at location 1.
  </apidoc:param>
      <apidoc:param name="length" type="xs:double" optional="true">
    The length in bytes of the new binary node.  
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>binary()</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">Usage is exactly like fn:substring except that it applies to a binary
  node rather than a string.</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  data(xdmp:subbinary(binary { xs:hexBinary("DEADBEEF") }, 3, 2))
  =&gt; xs:hexBinary("BEEF")
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="spawn" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Place the specified module on the task queue for evaluation.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="path" type="xs:string" optional="false">
    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 <em xmlns="http://www.w3.org/1999/xhtml">Application Developer's Guide</em>.
  </apidoc:param>
      <apidoc:param name="vars" type="item()*" optional="true">
    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.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
  The options node. The default value is (). The node must be in the 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> namespace.  See the 
  <a href="#xdmp:eval" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:eval</code></a> section for a list of options.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:usage>
    <p xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp:spawn</code> 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. </p>
    <p xmlns="http://www.w3.org/1999/xhtml">Once <code>xdmp:spawn</code> 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 <code>xdmp:spawn</code> 
    from a module that is performing an update transaction.  Once a module is 
    spawned, its evaluation is completely asynchronous of the statement in 
    which <code>xdmp:spawn</code> was called. Consequently,
    if you call <code>xdmp:spawn</code> 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 
    <code>xdmp:spawn</code> 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 <em>Developer's Guide</em>.</p>
</apidoc:usage>
    <apidoc:privilege>
<p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xdmp-spawn</code></p>
</apidoc:privilege>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:spawn("module.xqy", (), 
        &lt;options xmlns="xdmp:eval"&gt;
          &lt;modules&gt;{xdmp:modules-database()}&lt;/modules&gt;
	  &lt;root&gt;http://example.com/application/&lt;/root&gt;
         &lt;/options&gt;)
	 
  =&gt; Puts the module from the modules database with the 
     URI http://example.com/application/module.xqy 
     in the task server queue.</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="spawn-in" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  [DEPRECATED: use <a href="#xdmp:spawn" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:spawn</code></a> with the 
  database option instead] Place the specified module on the task 
  queue for evaluation.  It will be evaluated in the given database.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="path" type="xs:string" optional="false">
    The path, relative to the specified root, of the module to be executed.
  </apidoc:param>
      <apidoc:param name="ID" type="xs:unsignedLong" optional="false">
    The database ID, from <code xmlns="http://www.w3.org/1999/xhtml">xdmp:database("db_name")</code>, 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp:security-database()</code>, 
    or <code xmlns="http://www.w3.org/1999/xhtml">xdmp:schema-database()</code>.
  </apidoc:param>
      <apidoc:param name="vars" type="item()*" optional="true">
    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.
  </apidoc:param>
      <apidoc:param name="modules" type="xs:unsignedLong?" optional="true">
    The modules database that contains the module to invoke.
    The empty sequence specifies the current modules database.
  </apidoc:param>
      <apidoc:param name="root" type="xs:string?" optional="true">
    The root path for modules. 
    The empty sequence specifies the current root.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:usage>
    <p xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp:spawn-in</code> 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. </p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:spawn-in("example.xqy",
                324398742983742,
                (),
                xdmp:modules-database(),
                "http://example.com/application/")
  =&gt; ()
  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.
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="trace" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Signal a trace event.  
  If trace events are activated and the event is enabled, 
  the trace event is logged.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:string" optional="false">
    The trace event name.
  </apidoc:param>
      <apidoc:param name="value" type="item()*" optional="false">
    The trace event data.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:trace("My Application Event",$my-application-data)
  =&gt; ()
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="set" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Set the value of a variable to the specified expression. The 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:set</code> 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.
 </apidoc:summary>
    <apidoc:params>
      <apidoc:param name="variable" type="item()*" optional="false"> 
     A variable to set.
  </apidoc:param>
      <apidoc:param name="expr" type="item()*" optional="false">
     A value to set the variable.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:usage>
  When a variable is bound to a sequence in a <code xmlns="http://www.w3.org/1999/xhtml">for</code> loop, and when 
  that variable is changed by <code xmlns="http://www.w3.org/1999/xhtml">xdmp:set</code> in the <code xmlns="http://www.w3.org/1999/xhtml">return</code>
  clause, the change only affects the value for one iteration of the 
  <code xmlns="http://www.w3.org/1999/xhtml">for</code> 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 
  <code xmlns="http://www.w3.org/1999/xhtml">for</code> clause.  The value changes only after the 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:set</code> call is made. 
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
(: set the value of the variable $x 
   to 1234 and then print out $x :)

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

=&gt; 1234
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
(: 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)

=&gt; (1, 5, 1, 5, 2, 5, 2, 5)

</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
(: 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))

=&gt; (1, 1, 5, 5, 2, 2, 5, 5)

</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
(: every time the name of the input node changes,
   output the new name  :)

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

=&gt; (x, 1, 2, y, 3)

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="host" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the the ID of the host named in the parameter.  
  Returns the ID of the current host if no parameter is specified.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:string" optional="true">
    The name of the host.
    The default value is the name of the current host.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:host("foo.example.com")
  =&gt; 15495681647217162987
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="host-name" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the the name of the host ID specified as the parameter.  
  Returns the current host if no name is specified.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="ID" type="xs:unsignedLong" optional="false">
    A host ID.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:host-name(15495681647217162987)
  =&gt; foo.example.com
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="hosts" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of the IDs of all the hosts in the system.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:hosts()
   =&gt; 18263538320779601865
2760886727871312968
1551965607977434000
2714941248661564752
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="server" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:string" optional="true">
    The name of the App Server.
    The default value is the name of the current App Server.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong+</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:server("foo.example.com")
  =&gt; 15495681647217162987
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="servers" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of the IDs of all the App Servers in the system.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:servers()
   =&gt; 18263538320779601865
2760886727871312968
1551965607977434000
2714941248661564752
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="groups" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a sequence of the IDs of all the groups in the system.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:groups()
   =&gt; 12363538320723601865
2350822345151312968
7891965607973455300
2314941134541564752
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="group" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the the ID of the group specified in the parameter.  
  Returns the ID of the current group if no parameter is specified.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:string" optional="true">
    The name of the group.
    The default value is the name of the group the current host belongs to.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:group("Default")
  =&gt; 134722342511344334243
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="group-name" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the the name of the group with the given ID.  
  Returns the name of the current group if no parameter is specified.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:unsignedLong" optional="true">
    The id of the group.
    The default value is the id of the group the current host belongs to.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:group-name(134722342511344334243)
  =&gt; "Default"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="group-hosts" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:unsignedLong" optional="true">
    The ID of the group.
    The default value is the id of the group the current host belongs to.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:group-hosts(134722342511344334243)
  =&gt; 18263538320779601865
2760886727871312968
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="group-servers" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:unsignedLong" optional="true">
    The ID of the group.
    The default value is the ID of the group to which the current host belongs.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedLong*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:group-servers(xdmp:group("Default"))
   =&gt; 18263538320779601865
       2760886727871312968
       2714941248661564752
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="request" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the unique key of the current request.  
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:unsignedLong</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:request()
   =&gt; 18263538320779601865
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="modules-root" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the current root path for modules.
</apidoc:summary>
    <apidoc:params/>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:modules-root()
   =&gt; Docs
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="diacritic-less" type="builtin" lib="xdmp" category="Extension" subcategory="Search" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
Returns the specified string, converting all of the characters with diacritics 
to characters without diacritics.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="string" type="xs:string" optional="false">
  The string to convert.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:diacritic-less("José")
=&gt; Jose </pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="collation-canonical-uri" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc: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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="collation-uri" type="xs:string" optional="false">
  A collation URI.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:usage>
  If the specified collation URI is not a valid URI, an exception is thrown.
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:collation-canonical-uri("http://marklogic.com/collation/en/S3") 
=&gt; http://marklogic.com/collation/en
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="value" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Evaluate an expression in the context of the current evaluating statement.
  This differs from <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> in that <code xmlns="http://www.w3.org/1999/xhtml">xdmp:value</code>
  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.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="expr" type="xs:string" optional="false">
    The string representing an expression to evaluate.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">You can only evaluate expressions with <code>xdmp:value</code>; no 
  prolog definitions (namespace declarations, function definitions, 
  module imports, and so on) are allowed.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">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:</p>
  <pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:value("$y")</code></pre>
</apidoc:usage>
    <apidoc:privilege>
  <code xmlns="http://www.w3.org/1999/xhtml">http://marklogic.com/xdmp/privileges/xdmp-value</code>
</apidoc:privilege>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $var := 5 
  return
  xdmp:value("$var")
  =&gt; 5
  </pre>
</apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

xdmp:document-insert("/test.xml",
 &lt;root&gt;
   &lt;step1&gt;this is step1&lt;/step1&gt;
   &lt;step2&gt;this is step2&lt;/step2&gt;
 &lt;/root&gt;)
;

(: 
use xdmp:value to dynamically specify a step 
in an XPath expression
:)
for $x in ("step1", "step2")
return
/root/xdmp:value($x)

=&gt;
&lt;step1&gt;this is step1&lt;/step1&gt;
&lt;step2&gt;this is step2&lt;/step2&gt;
  </pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="unpath" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Evaluate a string as an XPath and return the corresponding node(s). 
  Any value that is the result of <code xmlns="http://www.w3.org/1999/xhtml">xdmp:path</code> is a 
  valid input to <code xmlns="http://www.w3.org/1999/xhtml">xdmp:unpath</code>.  Any invalid inputs 
  throw an <code xmlns="http://www.w3.org/1999/xhtml">XDMP-UNPATH</code> exception.  To evaluate non-XPath 
  expressions, use <code xmlns="http://www.w3.org/1999/xhtml">xdmp:value</code>.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="expr" type="xs:string" optional="false">
   The XPath expression string to evaluate. The XPath expression must be
   of the form returned by <code xmlns="http://www.w3.org/1999/xhtml">xdmp:path</code>.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:privilege>
  <code xmlns="http://www.w3.org/1999/xhtml">http://marklogic.com/xdmp/privileges/xdmp-value</code>
</apidoc:privilege>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:unpath("/bookstore/book/title")
  =&gt; &lt;title&gt;Querying XML&lt;/title&gt;
  </pre>
</apidoc:example>
    <apidoc:example>
<p xmlns="http://www.w3.org/1999/xhtml">The following example shows how you can use xdmp:unpath 
and specify namespace bindings that are not in the current query scope.</p>
<pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

let $doc := &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
              &lt;body&gt;&lt;p&gt;This is a document&lt;/p&gt;&lt;/body&gt;
            &lt;/html&gt;
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))

=&gt; &lt;p xmlns="http://www.w3.org/1999/xhtml"&gt;This is a document&lt;/p&gt;
  </pre>
</apidoc:example>
    <apidoc:example>
<p xmlns="http://www.w3.org/1999/xhtml">The following example shows that <code>xdmp:unpath</code>
will throw an error if the specified XPath expression
would never be returned by <code>xdmp:path</code>.</p>
<pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:unpath("/bookstore/book/title[@name eq 'Querying XML']")
  =&gt; throws the XDMP-UNPATH exception, because the specified 
     path expression would never be the output of xdmp:path.
  </pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="map" type="builtin" lib="map" category="map" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Creates a map.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="map" type="element(map:map)" optional="true">
    A serialized map element.</apidoc:param>
    </apidoc:params>
    <apidoc:return>map:map</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  map:map()
  =&gt; map:map(&lt;map xmlns="http://marklogic.com/xdmp/map"/&gt;)
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

let $map := 
&lt;map:map xmlns:map="http://marklogic.com/xdmp/map"&gt;
 &lt;map:entry&gt;
   &lt;map:key&gt;2&lt;/map:key&gt;
   &lt;map:value xsi:type="xs:string"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    world&lt;/map:value&gt;
 &lt;/map:entry&gt;
 &lt;map:entry&gt;
   &lt;map:key&gt;1&lt;/map:key&gt;
   &lt;map:value xsi:type="xs:string"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    hello&lt;/map:value&gt;
 &lt;/map:entry&gt;
&lt;/map:map&gt;
return
map:get(map:map($map), "2")
=&gt;
world
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="put" type="builtin" lib="map" category="map" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Put a value into a map at the given key.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="map" type="map:map" optional="false">
    A map.</apidoc:param>
      <apidoc:param name="key" type="xs:string" optional="false">
    A key. If the key is not unique, it will overwrite the existing key.
    </apidoc:param>
      <apidoc:param name="value" type="item()*" optional="false">
    A value.  If the value is the empty sequence, it will remove the
    key from the map.
    </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
let $map := map:map()
let $put := map:put($map, "some-key", 
                  &lt;info&gt;45683&lt;/info&gt;)
return
&lt;result&gt;{$map}&lt;/result&gt;

=&gt;
&lt;result&gt;
  &lt;map:map xmlns:map="http://marklogic.com/xdmp/map"&gt;
    &lt;map:entry&gt;
      &lt;map:key&gt;some-key&lt;/map:key&gt;
      &lt;map:value&gt;&lt;info&gt;45683&lt;/info&gt;&lt;/map:value&gt;
    &lt;/map:entry&gt;
  &lt;/map:map&gt;
&lt;/result&gt;
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="get" type="builtin" lib="map" category="map" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Get a value from a map.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="map" type="map:map" optional="false">
    A map.</apidoc:param>
      <apidoc:param name="key" type="xs:string" optional="false">
    A key.</apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  map:get($table, "some-key")
  =&gt; &lt;info&gt;45683&lt;/info&gt;
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="keys" type="builtin" lib="map" category="map" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Get the keys used in the map.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="map" type="map:map" optional="false">
    A map.</apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  map:keys($table)
  =&gt; ("some-key", "another key", "and another one")
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="clear" type="builtin" lib="map" category="map" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Clear a map.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="map" type="map:map" optional="false">
    A map.</apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  map:clear($table)
  =&gt; ()
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="count" type="builtin" lib="map" category="map" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the number of entries used in the map.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="map" type="map:map" optional="false">
    A map.</apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:unsignedInt</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  map:count($table)
  =&gt; 15
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="delete" type="builtin" lib="map" category="map" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Delete a value from a map.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="map" type="map:map" optional="false">
    A map.</apidoc:param>
      <apidoc:param name="key" type="xs:string" optional="false">
    A key.</apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  map:delete($table, "some-key")
  =&gt; ()
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="function" type="builtin" lib="xdmp" category="Extension" subcategory="Function Values" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a function value as an <code xmlns="http://www.w3.org/1999/xhtml">xdmp:function</code> type.  
  You can return an <code xmlns="http://www.w3.org/1999/xhtml">xdmp:function</code> from an expression or
  a function.  You can execute the function referred to by an
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:function</code> by passing the <code xmlns="http://www.w3.org/1999/xhtml">xdmp:function</code> value to 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:apply</code>.  
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="function" type="xs:QName" optional="false">
    The function QName, which includes its local name and namespace. If the 
    function is not found in the current query context or in the module 
    specified in the second parameter, then an exception is thrown.
  </apidoc:param>
      <apidoc:param name="module-path" type="xs:string?" optional="true">
    The optional path to the module where the function specified in the 
    first parameter is defined.  If the module-path is not supplied, the 
    function QName must be in-scope in the query context.  If the empty 
    sequence is supplied, the function behaves as if the parameter is not
    supplied (that is, it uses the in-scope query context).
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xdmp:function</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

xdmp:function(xs:QName("fn:empty"))
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

declare namespace admin="http://marklogic.com/xdmp/admin";

xdmp:function(xs:QName("admin:get-configuration"), 
      "/MarkLogic/admin.xqy")
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

let $function := xdmp:function(xs:QName("fn:concat"))
return
   xdmp:apply($function, "hello", " world")

=&gt; hello world
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="apply" type="builtin" lib="xdmp" category="Extension" subcategory="Function Values" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Applies an <code xmlns="http://www.w3.org/1999/xhtml">xdmp:function</code> with the given parameters.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="function" type="xdmp:function" optional="false">
    The xdmp:function value to be applied.
  </apidoc:param>
      <apidoc:param name="params-1-to-N" type="item()*" optional="true">
    The parameters to pass into the specified function value.  Specify one
    parameter for each parameter that the specified function takes, with the 
    first parameter corresponding to the first parameter in the specified
    function's signature, the second parameter corresponding to the second, 
    and so on.  Omit this parameter if the specified function takes no 
    parameters.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $function := xdmp:function(xs:QName("fn:empty"))
  return
    xdmp:apply($function, ())

  =&gt; true
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $function := xdmp:function(xs:QName("fn:concat"))
  return
    xdmp:apply($function, "hello", " world")

  =&gt; hello world
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $function := xdmp:function(xs:QName("fn:current-date"))
  return
    xdmp:apply($function)

  =&gt; 2009-02-14-08:00  (or whatever is the current date)
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="function-name" type="builtin" lib="xdmp" category="Extension" subcategory="Function Values" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the QName of the function(s) that the xdmp:function refers to.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="function" type="xdmp:function" optional="false">
    The xdmp:function value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:QName</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $fn := xdmp:function(xs:QName("fn:empty"))
  return
    xdmp:function-name($fn)
  ==&gt; "fn:empty"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="function-module" type="builtin" lib="xdmp" category="Extension" subcategory="Function Values" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the module location (if any) that the xdmp:function value refers to.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="function" type="xdmp:function" optional="false">
    The function value.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  let $fn := xdmp:function(xs:QName("admin:get-configuration"),"/MarkLogic/admin.xqy")
  return
    xdmp:function-module($fn)
  ==&gt; "/MarkLogic/admin.xqy"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="sleep" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Delays for a specific amount of time.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="msec" type="xs:unsignedInt" optional="false">
    The amount of time to sleep, in milliseconds.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>empty-sequence()</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:sleep(1000)
   =&gt; ()
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="with-namespaces" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Evaluates the expression in the context of a specific set of namespace
  bindings.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="nsbindings" type="xs:string*" optional="false">
  An alternating sequence of prefixes and URIs. Each prefix is bound to the 
  following URI.  If the prefix is the empty string, the following URI
  becaomes the default namespace of the resulting item(s). 
  </apidoc:param>
      <apidoc:param name="expr" type="item()*" optional="false">
    An expression to evaluate in the context of the given namespace bindings. 
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>item()*</apidoc:return>
    <apidoc:privilege>
  <code xmlns="http://www.w3.org/1999/xhtml">http://marklogic.com/xdmp/privileges/xdmp-with-namespaces</code>
</apidoc:privilege>
    <apidoc:example> <pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">

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

Returns:

   &lt;p:bar xmlns:p="http://marklogic.com/p/1.2"/&gt;
  
</pre></apidoc:example>
    <apidoc:example> <pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:with-namespaces(
   ('', 'x'),
   &lt;test&gt;
      &lt;test1&gt;hello&lt;/test1&gt;
   &lt;/test&gt;
=&gt;
&lt;test xmlns="x"&gt;
  &lt;test1&gt;hello&lt;/test1&gt;
&lt;/test&gt;

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="element-content-type" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns the schema-defined content-type of an element 
  ("empty", "simple", "element-only", or "mixed").
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="element" type="element()" optional="false">
    An element node.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:element-content-type(&lt;html xmlns="http://www.w3.org/1999/xhtml"/&gt;)
  =&gt; "element-only"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="pretty-print" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Returns a well-formatted XQuery module.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="xquery" type="xs:string" optional="false">
    An XQuery module to be reformatted.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp:pretty-print("for $x in 1 to 10 return $x")
   =&gt; "for $x in 1 to 10
       return $x"
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="xslt-invoke" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
   Executes an XSLT stylesheet against a node.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="path" type="xs:string" optional="false">
    The path of the stylesheet 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 
    <em xmlns="http://www.w3.org/1999/xhtml">Application Developer's Guide</em>. 
  </apidoc:param>
      <apidoc:param name="input" type="node()?" optional="false">
    The context node to which the stylesheet is applied.
  </apidoc:param>
      <apidoc:param name="params" type="map:map?" optional="true">
    The stylesheet parameter values for this evaluation.
    Each key in the map is a string representing the name of the parameter
    in Clark notation: "{namespaceURI}localname". The function
    <a href="#xdmp:key-from-QName" xmlns="http://www.w3.org/1999/xhtml">xdmp:key-from-QName</a>
    is a convenient way to generate these keys.
    Each entry in the map is the value of the corresponding parameter.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
  The options node. The default value is (). The node must be in the 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> namespace.  See the 
  <a href="#xdmp:eval" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:eval</code></a> section for a list of options.
  Additional options include:
  <dl xmlns="http://www.w3.org/1999/xhtml">
  <dt><p>&lt;mode&gt;</p></dt><dd>A QName specifying the initial 
  stylesheet mode to use (the <code>&lt;xsl:template&gt;</code> with
  the specified <code>mode</code> attribute).</dd>
  <dt><p>&lt;template&gt;</p></dt><dd>A QName specifying the name of 
  the initial template to apply.</dd>
  <dt><p>&lt;encoding&gt;</p></dt>
  <dd>Specifies the encoding to use when reading the stylesheet into MarkLogic
  Server.  Supported values include <code>UTF-8</code>, 
  <code>ISO-8859-1</code>, as well as many other popular encodings.  
  See the <em>Search Developer's Guide</em> 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 
  <code>encoding</code> option will be matched to an encoding name according
  to the Unicode Charset Alias Matching rules 
  (<a href="http://www.unicode.org/reports/tr22/#Charset_Alias_Matching">http://www.unicode.org/reports/tr22/#Charset_Alias_Matching</a>). 
  An automatic encoding detector will be used if the value <code>auto</code>
  is specified.
  If no encoding can be detected, the encoding defaults to UTF-8.
  </dd>
  </dl>
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:usage>
 <p xmlns="http://www.w3.org/1999/xhtml">When running an XSLT stylesheet in MarkLogic, you pass in a node on
  which the stylesheet operates.  Many stylesheets are written 
  to expect the initial node to be a document
  node.  In other XSLT processors, the node you pass to the stylesheet is 
  typically read in from the filesystem and is always treated as a document 
  node.  In MarkLogic, you often get the node to pass to the stylesheet as 
  the result of a query or a search, and the node  is not necessarily a 
  document node.  Therefore, if your stylesheet expects 
  the context node to be a document node, make sure to pass in a document 
  node and not an element node.  If you pass in an element node to a 
  stylesheet that has default template rules to expect a document node, 
  then you might miss the processing on the element you passed 
  in (because the stylesheet might expect the child node to be the root 
  element of the XML document, but if you passed in the root element instead of
  its parent document node, then the child nodes would be the children of the
  root element, causing the root element to miss its default processing).</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

(: 
this example requires a document named hello.xsl directly 
at the App Server root with the following content:

&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0"&gt;
    &lt;xsl:template match="/"&gt;
        &lt;xsl:text&gt;hello&lt;/xsl:text&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
:)
xdmp:xslt-invoke("/hello.xsl", document{ &lt;foo/&gt; })
=&gt;
hello
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml" ;

(: Hello World example for xslt:invoke, with a parameter.
   Assumes a stylesheet names params.xsl directly at
   the App Server root with the following content:
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:f="foo" xmlns:b="bar"
      version="2.0"&gt;
    &lt;xsl:param name="f:pName"/&gt;
    &lt;xsl:param name="b:bName"/&gt;
    &lt;xsl:param name="cName"/&gt;
    &lt;xsl:param name="greeting" select="'Hi there '"/&gt;
    &lt;xsl:template match="/"&gt;
       &lt;output&gt;
         &lt;xsl:copy-of select="node"/&gt;
         &lt;greeting&gt;&lt;xsl:value-of select="$greeting"/&gt;&lt;/greeting&gt;
         &lt;param&gt;&lt;xsl:value-of select="$f:pName"/&gt;&lt;/param&gt;
         &lt;param&gt;&lt;xsl:value-of select="$b:bName"/&gt;&lt;/param&gt;
         &lt;param&gt;&lt;xsl:value-of select="$cName"/&gt;&lt;/param&gt;
       &lt;/output&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
:)

let $params := map:map()
let $_put := map:put(
                    $params,
                    xdmp:key-from-QName(fn:QName("foo", "pName")),
                    "Stephen")
let $_put := map:put(
                    $params,
                    xdmp:key-from-QName(fn:QName("bar", "bName")),
                    "Ron")
let $_put := map:put(
                    $params,
                    "cName",
                    "Dave")
return
xdmp:xslt-invoke("/params.xsl",
    document { &lt;node&gt;Hello World&lt;/node&gt; },
    $params)
=&gt;
&lt;?xml version="1.0" encoding="ASCII"?&gt;
&lt;output xmlns:f="foo" xmlns:b="bar"&gt;
  &lt;node&gt;Hello World&lt;/node&gt;
  &lt;greeting&gt;Hi there &lt;/greeting&gt;
  &lt;param&gt;Stephen&lt;/param&gt;
  &lt;param&gt;Ron&lt;/param&gt;
  &lt;param&gt;Dave&lt;/param&gt;
&lt;/output&gt;

</pre></apidoc:example>
  </apidoc:function><apidoc:function name="xslt-eval" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
   Executes an XSLT stylesheet against a node.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="stylesheet" type="element()" optional="false">
    The stylesheet to be executed.
  </apidoc:param>
      <apidoc:param name="input" type="node()?" optional="false">
    The context node to which the stylesheet is applied.
  </apidoc:param>
      <apidoc:param name="params" type="map:map?" optional="true">
    The stylesheet parameter values for this evaluation.
    Each key in the map is a string representing the name of the parameter
    in Clark notation: "{namespaceURI}localname". The function
    <a href="#xdmp:key-from-QName" xmlns="http://www.w3.org/1999/xhtml">xdmp:key-from-QName</a>
    is a convenient way to generate these keys.
    Each entry in the map is the value of the corresponding parameter.
  </apidoc:param>
      <apidoc:param name="options" type="node()?" optional="true">
  The options node. The default value is (). The node must be in the 
  <code xmlns="http://www.w3.org/1999/xhtml">xdmp:eval</code> namespace.  See the 
  <a href="#xdmp:eval" xmlns="http://www.w3.org/1999/xhtml"><code>xdmp:eval</code></a> section for a list of options.
  Additional options include:
  <dl xmlns="http://www.w3.org/1999/xhtml">
  <dt><p>&lt;mode&gt;</p></dt><dd>A QName specifying the initial 
  stylesheet mode to use (the <code>&lt;xsl:template&gt;</code> with
  the specified <code>mode</code> attribute).</dd>
  <dt><p>&lt;template&gt;</p></dt><dd>A QName specifying the name of 
  the initial template to apply.</dd>
  </dl>
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>document-node()*</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">When creating the <code>xsl:stylesheet</code> element that is the 
  stylesheet parameter to <code>xdmp:xslt-eval</code>, keep in mind that 
  it has to first be parsed by XQuery before
  it is evaluated as a stylesheet.  Therefore, any characters in the stylesheet
  that require escaping in XQuery must be escaped, otherwise you get an error
  in the XQuery.  For example, if the stylesheet has any curly braces 
  ( { or } ), you must escape the curly braces (with curly braces). For
  an example, see <a href="#xslteval4">the example</a> below.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">When running an XSLT stylesheet in MarkLogic, you pass in a node on
  which the stylesheet operates.  Many stylesheets are written 
  to expect the initial node to be a document
  node.  In other XSLT processors, the node you pass to the stylesheet is 
  typically read in from the filesystem and is always treated as a document 
  node.  In MarkLogic, you often get the node to pass to the stylesheet as 
  the result of a query or a search, and the node  is not necessarily a 
  document node.  Therefore, if your stylesheet expects 
  the context node to be a document node, make sure to pass in a document 
  node and not an element node.  If you pass in an element node to a 
  stylesheet that has default template rules to expect a document node, 
  then you might miss the processing on the element you passed 
  in (because the stylesheet might expect the child node to be the root 
  element of the XML document, but if you passed in the root element instead of
  its parent document node, then the child nodes would be the children of the
  root element, causing the root element to miss its default processing).</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
let $foo-to-bar :=
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0"&gt;
    &lt;xsl:template match="foo"&gt;
      &lt;bar&gt;
        &lt;xsl:apply-templates select="node()"/&gt;
      &lt;/bar&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
return xdmp:xslt-eval($foo-to-bar,
  &lt;stuff&gt;
   &lt;one/&gt;
   &lt;foo/&gt;
   &lt;two/&gt;
   &lt;foo&gt;&lt;blah&gt;42&lt;/blah&gt;&lt;/foo&gt;
   &lt;bar&gt;22&lt;/bar&gt;
  &lt;/stuff&gt;)/element()
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml" ;

(: Hello World example for xslt:eval, with a parameter :)

let $params := map:map()
let $_put := map:put(
                    $params,
                    xdmp:key-from-QName(fn:QName("foo", "pName")),
                    "Stephen")
let $_put := map:put(
                    $params,
                    xdmp:key-from-QName(fn:QName("bar", "bName")),
                    "Ron")
let $_put := map:put(
                    $params,
                    "cName",
                    "Dave")
return
  xdmp:xslt-eval(
    &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:f="foo" xmlns:b="bar"
      version="2.0"&gt;
    &lt;xsl:param name="f:pName"/&gt;
    &lt;xsl:param name="b:bName"/&gt;
    &lt;xsl:param name="cName"/&gt;
    &lt;xsl:param name="greeting" select="'Hi there '"/&gt;
    &lt;xsl:template match="/"&gt;
       &lt;output&gt;
         &lt;xsl:copy-of select="node"/&gt;
         &lt;greeting&gt;&lt;xsl:value-of select="$greeting"/&gt;&lt;/greeting&gt;
         &lt;param&gt;&lt;xsl:value-of select="$f:pName"/&gt;&lt;/param&gt;
         &lt;param&gt;&lt;xsl:value-of select="$b:bName"/&gt;&lt;/param&gt;
         &lt;param&gt;&lt;xsl:value-of select="$cName"/&gt;&lt;/param&gt;
       &lt;/output&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;,
  document { &lt;node&gt;Hello World&lt;/node&gt; },
  $params)
=&gt;
&lt;?xml version="1.0" encoding="ASCII"?&gt;
&lt;output xmlns:f="foo" xmlns:b="bar"&gt;
  &lt;node&gt;Hello World&lt;/node&gt;
  &lt;greeting&gt;Hi there &lt;/greeting&gt;
  &lt;param&gt;Stephen&lt;/param&gt;
  &lt;param&gt;Ron&lt;/param&gt;
  &lt;param&gt;Dave&lt;/param&gt;
&lt;/output&gt;
</pre></apidoc:example>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml" ;

(: example that passes in a QName for a mode :)
xdmp:xslt-eval(
    &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="2.0"&gt;
    &lt;xsl:template match="/"&gt;
       &lt;output&gt;this has no mode&lt;/output&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="/" mode="my-mode"&gt;
      &lt;debug&gt;this has a mode&lt;/debug&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;, 
  document { &lt;node&gt;Hello World&lt;/node&gt; },
  (),
  &lt;options xmlns="xdmp:eval"&gt;
    &lt;mode&gt;{fn:QName("", "my-mode")}&lt;/mode&gt;
  &lt;/options&gt;)
=&gt;
&lt;?xml version="1.0" encoding="ASCII"?&gt;
&lt;debug&gt;this has a mode&lt;/debug&gt;

</pre></apidoc:example>
    <apidoc:example><a id="xslteval4" xmlns="http://www.w3.org/1999/xhtml"></a><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";

(:
  Note the esacped curly braces ( {{ and }} on the name attribute
  of xsl:element), as the stylesheet must first be parsed by XQuery 
  before it is evaluated as a stylesheet.  If you do not escape
  the curly braces, the query throws the XQuery exception:
  [1.0-ml] XDMP-CONTEXT: (err:XPDY0002) Expression depends on the context 
           where none is defined
  That is because, without the escaped braces, XQuery tries to evaluate
  the expression in the name attribute, but there is no context for it.
:)
xdmp:xslt-eval(
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="2.0"&gt;
    &lt;xsl:template match="foo"&gt;
     &lt;xsl:element name="{{name(.)}}"/&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
,
document{ &lt;foo&gt;something goes here&lt;/foo&gt;} )
=&gt;
&lt;?xml version="1.0" encoding="ASCII"?&gt;
&lt;foo/&gt;
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="key-from-QName" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
   Construct a context-independent string from a QName.  This string is
   of the form "{namespaceURI}localname" and is suitable for use as a map
   key.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="name" type="xs:QName" optional="false">
  The QName to compute a key for.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:usage>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="QName-from-key" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
   Construct a QName from a string of the form "{namespaceURI}localname".
   This function is useful for constructing Clark notation
   parameters for the <a href="#xdmp:xslt-eval" xmlns="http://www.w3.org/1999/xhtml">xdmp:xslt-eval</a>
   and <a href="#xdmp:xslt-invoke" xmlns="http://www.w3.org/1999/xhtml">xdmp:xslt-invoke</a>
   functions.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="key" type="xs:string" optional="false">
  The string from which to construct a QName.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:QName</apidoc:return>
    <apidoc:usage>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xquery version "1.0-ml";
(: returns the Clark notation form of the QName :)

xdmp:key-from-QName(xs:QName("fn:foo"))
=&gt;
{http://www.w3.org/2005/xpath-functions}foo
</pre></apidoc:example>
  </apidoc:function><apidoc:function name="encoding-language-detect" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Analyzes binary, text, or XML data and suggests possible pairs of encoding 
  and language, with a confidence score for each pair. Scores of 10 and 
  above are high confidence recommendations.
  The results are given in order of decreasing score.
  Accuracy may be poor for short documents.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="document" type="node()" optional="false">
    Node to be analyzed for possible encodings and languages.  If the node is
    an XML element or document node, the function takes the string value
    of the specified node (equivalent of <code xmlns="http://www.w3.org/1999/xhtml">fn:string($node)</code>) to
    detect the encoding and language.
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>element()*</apidoc:return>
    <apidoc:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">If the input is very small (for example, less than two words), then
  <code>xdmp:encoding-language-detect</code> returns the empty sequence.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">For best results, the input should be at least several hundred bytes.</p>
</apidoc:usage>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:encoding-language-detect(xdmp:document-get("/tmp/unknown.dat"))
=&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;en&lt;/language&gt;
  &lt;score&gt;9.834&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;it&lt;/language&gt;
  &lt;score&gt;8.976&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;sl&lt;/language&gt;
  &lt;score&gt;8.265&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;ro&lt;/language&gt;
  &lt;score&gt;7.975&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;fr&lt;/language&gt;
  &lt;score&gt;7.933&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;da&lt;/language&gt;
  &lt;score&gt;7.656&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;nb&lt;/language&gt;
  &lt;score&gt;7.603&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;nl&lt;/language&gt;
  &lt;score&gt;7.331&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;es&lt;/language&gt;
  &lt;score&gt;7.167&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;ca&lt;/language&gt;
  &lt;score&gt;7.143&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;de&lt;/language&gt;
  &lt;score&gt;6.605&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;sr&lt;/language&gt;
  &lt;score&gt;6.595&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;sk&lt;/language&gt;
  &lt;score&gt;6.455&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;cs&lt;/language&gt;
  &lt;score&gt;6.438&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;nn&lt;/language&gt;
  &lt;score&gt;6.337&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;sv&lt;/language&gt;
  &lt;score&gt;5.827&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;pt&lt;/language&gt;
  &lt;score&gt;5.762&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;hu&lt;/language&gt;
  &lt;score&gt;5.356&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;hr&lt;/language&gt;
  &lt;score&gt;4.941&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1250&lt;/encoding&gt;
  &lt;language&gt;pl&lt;/language&gt;
  &lt;score&gt;4.693&lt;/score&gt;
&lt;/encoding-language&gt;
&lt;encoding-language xmlns="xdmp:encoding-language-detect"&gt;
  &lt;encoding&gt;windows-1252&lt;/encoding&gt;
  &lt;language&gt;fi&lt;/language&gt;
  &lt;score&gt;3.885&lt;/score&gt;
&lt;/encoding-language&gt;
</pre>
</apidoc:example>
  </apidoc:function><apidoc:function name="binary-decode" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions">
    <apidoc:summary>
  Converts an encoded byte sequence, passed in as a binary node, from the
  specified encoding to a unicode string.
</apidoc:summary>
    <apidoc:params>
      <apidoc:param name="encoded" type="node()" optional="false">
     A binary node containing the encoded stream.
  </apidoc:param>
      <apidoc:param name="encoding-name" type="xs:string" optional="false">
    Specifies the encoding to use when decoding the document.
    Supported values include <code xmlns="http://www.w3.org/1999/xhtml">UTF-8</code> and <code xmlns="http://www.w3.org/1999/xhtml">ISO-8859-1</code>.
    The string specifed for the <code xmlns="http://www.w3.org/1999/xhtml">encoding</code> option will be matched
    to a registered encoding name using the Unicode Charset Alias Matching rules 
    (<a href="http://www.unicode.org/reports/tr22/#Charset_Alias_Matching" xmlns="http://www.w3.org/1999/xhtml">http://www.unicode.org/reports/tr22/#Charset_Alias_Matching</a>). 
  </apidoc:param>
    </apidoc:params>
    <apidoc:return>xs:string</apidoc:return>
    <apidoc:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp:binary-decode(
   fn:doc("binary_doc_encoded_as_ShiftJIS.dat")/node(),
          "sjis")
=&gt; contents of document after decoding, in unicode characters
</pre></apidoc:example>
  </apidoc:function></apidoc:module>