MarkLogic Server
XQUERY API DOCUMENTATION
3.0
This page was generated
January 9, 2006
2:56 PM
XQuery Built-In and Modules Function Reference

Built-In: UpdateBuiltins

The update built-in functions are XQuery functions to perform update-related tasks such as loading documents, inserting nodes into documents, and so on.
Function Summary
xdmp:collection-delete Deletes from the database every document in a collection.
xdmp:directory-create Creates a directory.
xdmp:directory-delete Deletes a directory and its children from the database.
xdmp:document-add-collections Adds the named document to the given collections.
xdmp:document-add-permissions Adds the given permissions to the given document.
xdmp:document-add-properties Adds a sequence of properties to the properties of a document.
xdmp:document-delete Deletes a document from the database.
xdmp:document-insert Inserts a new document into the database if a document with the specified URI does not already exist.
xdmp:document-load Inserts a new document with the specified URI.
xdmp:document-remove-collections Removes the named document from the given collections.
xdmp:document-remove-permissions Removes the given permissions from the named document.
xdmp:document-remove-properties Removes a sequence of properties from the properties of a document.
xdmp:document-set-collections Sets the named document to belong to the given collections.
xdmp:document-set-permissions Sets the permissions on the named document to the given permissions.
xdmp:document-set-properties Sets the properties of a document to the given sequence of elements.
xdmp:document-set-property Sets a property on a document.
xdmp:document-set-quality Sets the quality of the document with the given URI.
xdmp:load [DEPRECATED] Inserts a new document from the XML file at $path if a document with the specified URI does not already exist.
xdmp:lock-acquire Aquire a lock on a document or directory for an extended amount of time.
xdmp:lock-release Unlock a document.
xdmp:merge Starts merging the database forests.
xdmp:merging Returns the forest IDs of any currently merging database forests.
xdmp:node-delete Deletes a node from the database.
xdmp:node-insert-after Adds an immediately following sibling to a node.
xdmp:node-insert-before Adds an immediately preceding sibling to a node.
xdmp:node-insert-child Adds a new last child to a node.
xdmp:node-replace Replaces a node.
xdmp:save Serializes a node and saves it as an XML text file.
Function Detail
xdmp:collection-delete(
$uri as xs:string
)  as  empty()
Summary:

Deletes from the database every document in a collection.

Parameters:
$uri : The URI of the collection to be deleted.

Example:
  xdmp:collection-delete("collection-uri")

xdmp:directory-create(
$uri as xs:string,
[$permissions as element(sec:permission)*],
[$collections as xs:string*],
[$quality as xs:int]
)  as  empty()
Summary:

Creates a directory. If security is enabled, the document permissions and collections are set to the given parameters, if supplied. Otherwise, the current user's default permissions and/or collections are applied. If the beginning of the the document URI is protected, the user must have access to that URI privilege. If the directory URI does not end with a '/' one is added. If the directory already exists, then nothing is done.

Parameters:
$uri : The URI of the directory to be inserted.
$permissions (optional): Security permission elements corresponding to the permissions for the document.
$collections (optional): The collections to which the new directory belongs.
$quality (optional): The quality of this document. A positive value increases the relevance score of the document in text search functions. The converse is true for a negative value. The default value is 0.

Example:
xdmp:directory-create("http://marklogic.com/a/",
            (xdmp:permission("development", "update"),
             xdmp:permission("qa", "read")),
             "http://marklogic.com/directories")
  

xdmp:directory-delete(
$uri as xs:string
)  as  empty()
Summary:

Deletes a directory and its children from the database.

Parameters:
$uri : The URI of the directory to be deleted.

Usage Notes:

If you delete a directory, the directory and all of its children are deleted, including all child documents and directories. A child document or directory of a given directory is one whose URI begins with the same string as the directory URI.

Example:
  xdmp:directory-delete("http://example.com/")

xdmp:document-add-collections(
$uri as xs:string,
$collections as xs:string*
)  as  empty()
Summary:

Adds the named document to the given collections. For each collection that is protected, the user must have permissions to update that collection or have the any-collection privilege. For each unprotected collection, the user must have the unprotected-collection privilege.

Parameters:
$uri : The document URI.
$collections : A set of collection URI's.

Example:
  xdmp:document-add-collections(
    "/example.xml", 
    ("http://examples.com", "http://marklogic.com"))

xdmp:document-add-permissions(
$uri as xs:string,
$permissions as element(sec:permission)*
)  as  empty()
Summary:

Adds the given permissions to the given document. User must have update or insert permissions on the document.

Parameters:
$uri : The document URI.
$permissions : Permission elements.

Example:
  xdmp:document-add-permissions(
    "/example.xml", 
    (xdmp:permission("development", "update"), 
     xdmp:permission("qa", "read")))

xdmp:document-add-properties(
$uri as xs:string,
$props as element()*
)  as  empty()
Summary:

Adds a sequence of properties to the properties of a document.

Parameters:
$uri : The URI of the document to be inserted.
$props : The properties to add.

Example:
  xdmp:document-add-properties(
         "example.xml", 
         (<priority>1</priority>,
          <status>unedited</status>))
  => ()

xdmp:document-delete(
$uri as xs:string
)  as  empty()
Summary:

Deletes a document from the database.

Parameters:
$uri : The URI of the document to be deleted.

Usage Notes:

The xdmp:document-delete function deletes a document and all of its properties, except the directory property; it does not delete a directory with the same URI as the document being deleted. To delete a directory, use the xdmp:directory-delete function.

If a document does not exist at the specified URI, xdmp:document-delete returns an error.


Example:
xdmp:document-delete("example.xml")

xdmp:document-insert(
$uri as xs:string,
$root as node(),
[$permissions as element(sec:permission)*],
[$collections as xs:string*],
[$quality as xs:int],
[$forest-ids as xs:unsignedLong*]
)  as  empty()
Summary:

Inserts a new document into the database if a document with the specified URI does not already exist. Otherwise, the function replaces the content in the existing file as an update operation.

Parameters:
$uri : The URI of the document to be inserted.
$root : The root node. The root node can be one of XML format, binary (BLOB) format, or text (CLOB) format.
$permissions (optional): Security permission elements corresponding to the permissions for the document. If not supplied, the current user's default permissions are applied. The default value used for $permissions can be obtained by calling xdmp:default-permissions().
$collections (optional): The collection URIs for collections to which this document belongs. If not supplied, the document is added to the current user's default collections. The default value used for $collections can be obtained by calling xdmp:default-collections().
$quality (optional): The quality of this document. A positive value increases the relevance score of the document in text search functions. The converse is true for a negative value. The default value is 0.
$forest-ids (optional): Specifies the ID of the forest in which this document is inserted. If the document already exists in the database it will remain in its existing forest. If no such forest exists, an error is raised. If multiple forests are specified, the document is inserted into one of the specifed forests.

Example:
  xdmp:document-insert(
         "/example.xml", <a>aaa</a>,
            (xdmp:permission("editor", "read"), 
             xdmp:permission("editor", "update")),
         "http://examples.com")
Example:
  xdmp:document-insert(
         "/example.xml", 
	 <a>aaa</a>,
         xdmp:default-permissions(), 
         xdmp:default-collections(), 
	 10)

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

Inserts a new document with the specified URI. If a document already exists at the URI, the function replaces the content in the existing document as an update operation.

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

The xdmp:document-load options include:

<uri>

The URI of the document to be loaded. If omitted, then the location is used for the URI.

<permissions>

Security permission elements corresponding to the permissions for the document. If not supplied, the current user's default permissions are applied. The default value used for $permissions can be obtained by calling xdmp:default-permissions().

<collections>

The collection URIs for collections to which this document belongs. If not supplied, the document is added to the current user's default collections (the collections returned from xdmp:default-collections()). The <collections> element consists of one or more <collection> child elements. For example:
    <collections>
      <collection>myCollection1</collection>
      <collection>myCollection2</collection>
    </collections> 

<quality>

The quality of this document. A positive value increases the relevance score of the document in text search functions. The converse is true for a negative value. The default value is 0.

<default-namespace>

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

<repair>

A value of full specifies that malformed XML content be repaired. A value of none specifies that malformed XML content is rejected. This option has no effect on binary or text documents.

<format>

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

<lang>

A value of en specifies that the document is in english.

<forests>

Specifies the ID of the forest in which this document is inserted. Each forest ID is in a the <forest> child element and is of type xs:unsignedLong. If the document already exists in the database, it will remain in its existing forest. If no such forest exists, an error is raised. If multiple forests are specified, the document is inserted into one of the specifed forests.

Example:
xdmp:document-load("c:\myFile.xml", 
    <options xmlns="xdmp:document-load">
      <uri>/documents/myFile.xml</uri>
      <repair>none</repair>
      <permissions>{xdmp:default-permissions()}</permissions>
    </options>)

=> Loads the document with a URI "/documents/myFile.xml"
   and does not perform tag repair during the load.


Example:
xdmp:document-load("http://myCompany.com/file.xml", 
    <options xmlns="xdmp:document-load"
             xmlns:http="xdmp:http">
      <uri>/documents/myFile.xml</uri>
      <repair>none</repair>
      <permissions>{xdmp:default-permissions()}</permissions>
      <format>xml</format>
      <http:authentication>
          <http:username>user</http:username>
          <http:password>pass</http:password>
      </http:authentication>
    </options>)

=> Loads the document with a URI "/documents/myFile.xml"
   from the server http://myCompany.com, sending the
   credentials user/pass. Tag repair is not performed
   during the load, and the document is loaded as xml.


Example:
xdmp:document-load("c:\myFile.xml",
    <options xmlns="xdmp:document-load">
       <uri>/documents/myFile.xml</uri>
       <permissions>{xdmp:default-permissions()}</permissions> 
       <collections>
          <collection>myCollection1</collection>
	  <collection>myCollection2</collection>
       </collections> 
       <repair>full</repair>
       <forests>
         <forest>{xdmp:forest("myForest")}</forest>
       </forests>
    </options> )

=> Loads the document with a URI "/documents/myFile.xml"
   performing tag repair during the load, adding the 
   document to the "myCollection1" and "myCollection2"
   collections, and loading the document into the forest 
   named "myForest".



xdmp:document-remove-collections(
$uri as xs:string,
$collections as xs:string*
)  as  empty()
Summary:

Removes the named document from the given collections. For each collection that is protected, the user must have permissions to update that collection or have the any-collection privilege. For each unprotected collection, the user must have the unprotected-collection privilege.

Parameters:
$uri : The document URI.
$collections : A set of collection URI's.

Example:
  xdmp:document-remove-collections(
    "/example.xml", 
    ("http://examples.com", "http://marklogic.com"))

xdmp:document-remove-permissions(
$uri as xs:string,
$permissions as element(sec:permission)*
)  as  empty()
Summary:

Removes the given permissions from the named document. User must have update permissions on the document.

Parameters:
$uri : The document URI.
$permissions : Permission elements.

Example:
  xdmp:document-remove-permissions(
    "/example.xml", 
    (xdmp:permission("development", "update"), 
     xdmp:permission("qa", "read")))

xdmp:document-remove-properties(
$uri as xs:string,
$property-names as xs:QName*
)  as  empty()
Summary:

Removes a sequence of properties from the properties of a document. If properties with the QNames given do not exist, nothing is done.

Parameters:
$uri : The URI of the document to be inserted.
$property-names : The properties to remove.

Example:
  xdmp:document-remove-properties(
         "example.xml", 
         (fn:expanded-QName("", "priority"),
          fn:expanded-QName("", "status")))
  => ()

xdmp:document-set-collections(
$uri as xs:string,
$collections as xs:string*
)  as  empty()
Summary:

Sets the named document to belong to the given collections. For each collection that is protected, the user must have permissions to update that collection or have the any-collection privilege. For each unprotected collection, the user must have the unprotected-collection privilege.

Parameters:
$uri : The document URI.
$collections : A set of collection URI's.

Example:
  xdmp:document-set-collections(
    "/example.xml", 
    ("http://examples.com", "http://marklogic.com"))

xdmp:document-set-permissions(
$uri as xs:string,
$permissions as element(sec:permission)*
)  as  empty()
Summary:

Sets the permissions on the named document to the given permissions. User must have update permissions on the document.

Parameters:
$uri : The document URI.
$permissions : Permission elements.

Example:
  xdmp:document-set-permissions(
    "/example.xml", 
    (xdmp:permission("development", "update"), 
     xdmp:permission("qa", "read")))

xdmp:document-set-properties(
$uri as xs:string,
$props as element()*
)  as  empty()
Summary:

Sets the properties of a document to the given sequence of elements. Each element QName is the property name and the element value is the property value. Modifying properties requires update permissions on a document.

Parameters:
$uri : The URI of the document to be inserted.
$props : The properties to set. Replaces any properties already set on the document.

Example:
  xdmp:document-set-properties(
         "example.xml", 
         (<priority>1</priority>,
          <status>unedited</status>))
  => ()

xdmp:document-set-property(
$uri as xs:string,
$prop as element()
)  as  empty()
Summary:

Sets a property on a document. If any properties with the same property QName exist, they are replaced with the new property. If no properties exist with the same QName, the new property is added.

Parameters:
$uri : The document URI for the property setting.
$prop : The property to set.

Example:
xdmp:document-set-property(
  "http://marklogic.com/a/example.xml",
  <priority xmlns="http://example.com">5</priority>)
  

xdmp:document-set-quality(
$uri as xs:string,
$quality as xs:int
)  as  empty()
Summary:

Sets the quality of the document with the given URI. If the quality of the document is positive, the relevance score of the document is increased in text search functions. The converse is true for "negative" quality.

Parameters:
$uri : The URI of the document to which you are setting the quality.
$quality : The quality to which to set the document.

Example:
  xdmp:document-set-quality(
    "http://www.marklogic.com/test.xml",10)
  => ()

xdmp:load(
$path as xs:string,
[$uri as xs:string],
[$permissions as element(sec:permission)*],
[$collections as xs:string*],
[$quality as xs:int],
[$default-namespace as xs:string],
[$options as xs:string*],
[$forest-ids as xs:unsignedLong*]
)  as  empty()
Summary:

[DEPRECATED] Inserts a new document from the XML file at $path if a document with the specified URI does not already exist. Otherwise, the function replaces the content in the existing document as an update operation.

Parameters:
$path : The path to the input file. The path can be fully qualifed or relative. Relative pathnames are resolved from the directory in which MarkLogic Server is installed.
$uri (optional): The URI of the document to be loaded. If omitted, then the pathname is used.
$permissions (optional): Security permission elements corresponding to the permissions for the document. If not supplied, the current user's default permissions are applied. The default value used for $permissions can be obtained by calling xdmp:default-permissions(). To specify no permissions, enter the empty sequence ().
$collections (optional): The collection URIs for collections to which this document belongs. If not supplied, the document is added to the current user's default collections. The default value used for $collections can be obtained by calling xdmp:default-collections(). To specify no collections, enter the empty sequence ().
$quality (optional): The quality of this document. A positive value increases the relevance score of the document in text search functions. The converse is true for a negative value. The default value is 0.
$default-namespace (optional): If $default-namespace is specified and the root node of the loaded document does not explicitly specify a namespace, $default-namespace will be applied to the root node. The default value for $default-namespace is "".
$options (optional): The options for loading this document. The default value is ().

Options include:

"repair-full"
Specifies that malformed XML content be repaired during loading. This option has no effect on binary or text documents.
"repair-none"
Specifies that malformed XML content be rejected during loading. This option has no effect on binary or text documents.
"format-text"
Specifies to load the document as a text document, regardless of the URI specified.
"format-binary"
Specifies to load the document as a binary document, regardless of the URI specified.
"format-xml"
Specifies to load the document as an XML document, regardless of the URI specified.
"lang=en"
Specifies that the document is in english.
$forest-ids (optional): Specifies the ID of the forest in which this document is inserted. If the document already exists in the database, it will remain in its existing forest. If no such forest exists, an error is raised. If multiple forests are specified, the document is inserted into one of the specifed forests.

Required Privilege:

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

If a new document is inserted, the unprotected-uri privilege (only if the URI is not protected), the any-uri privilege, or an appropriate URI privilege is also needed.

Usage Notes:

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

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


Example:
  xdmp:load("/home/test/example.xml", "/example.xml", 
            (xdmp:permission("editor", "read"), 
             xdmp:permission("editor", "update")),
            "http://examples.com",
            10,"http://www.marklogic.com/default")
Example:
  xdmp:load("/home/test/example.xml", 
	    "/example.xml", 
            xdmp:default-permissions(), 
            xdmp:default-collections(),
            0, 
	    "", 
	    "repair-none")

xdmp:lock-acquire(
$uri as xs:string,
[$scope as xs:string],
[$depth as xs:string],
[$owner as item()],
[$timeout as xs:unsignedLong?]
)  as  empty()
Summary:

Aquire a lock on a document or directory for an extended amount of time. Locks restrict updates to a document or directory.

Parameters:
$uri : The URI of the document to be locked.
$scope (optional): The lock scope ("exclusive" or "shared")
$depth (optional): The lock depth ("0" or "infinity"). "0" locks the URI only, and "infinity" locks the URI (the document or directory) and all of its children.
$owner (optional): Alternate description of the lock owner.
$timeout (optional): Requested lock timeout in seconds (() for infinite).

Usage Notes:

If you lock a directory specifying a depth of "infinity", the directory and all of it children (all documents and directories with a URI started with the locked directory) are locked. You will not be able to add any children to the directory until the lock is released.

Example:
  xdmp:lock-acquire("/example.xml", 
           "exclusive",
           "0",
           <DAV:href>http://example.com/~user</DAV:href>,
           xs:unsignedLong(120))
  => ()

xdmp:lock-release(
$uri as xs:string
)  as  empty()
Summary:

Unlock a document.

Parameters:
$uri : The URI of the document to be locked.

Example:
xdmp:lock-release("/example.xml") => ()

xdmp:merge( ) as empty()
Summary:

Starts merging the database forests.

Required Privilege:

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

Example:
  xdmp:merge()
   => ()

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

Returns the forest IDs of any currently merging database forests.

Required Privilege:

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

Example:
  xdmp:merging()
   => 23487234872334

xdmp:node-delete(
$old as node()
)  as  empty()
Summary:

Deletes a node from the database. On-the-fly constructed nodes cannot be deleted.

Parameters:
$old : The node to be deleted.

Example:
  xdmp:document-insert("/example.xml", 
    <a><b>bbb</b></a>);
  xdmp:node-delete(doc("/example.xml")/a/b);
  doc("/example.xml")
 => 
  <a/>

xdmp:node-insert-after(
$sibling as node(),
$new as node()
)  as  empty()
Summary:

Adds an immediately following sibling to a node.

Parameters:
$sibling : The sibling node to be followed by the new node.
$new : The new node to be inserted.

Usage Notes:

Attribute nodes cannot be followed by non-attribute nodes. Non-attribute nodes cannot be followed by attribute nodes. Element nodes cannot have document node children. Document nodes cannot have multiple element node children. On-the-fly constructed nodes cannot be updated.

Example:
  xdmp:document-insert("/example.xml", 
    <a><b>bbb</b></a>);
  xdmp:node-insert-after(doc("/example.xml")/a/b, 
    <c>ccc</c>);
  doc("/example.xml")
 => 
  <a><b>bbb</b><c>ccc</c></a>

xdmp:node-insert-before(
$sibling as node(),
$new as node()
)  as  empty()
Summary:

Adds an immediately preceding sibling to a node.

Parameters:
$sibling : The sibling node to be preceded by the new node.
$new : The new node to be inserted.

Usage Notes:

Attribute nodes cannot be preceded by non-attribute nodes. Non-attribute nodes cannot be preceded by attribute nodes. Element nodes cannot have document node children. Document nodes cannot have multiple element node children. On-the-fly constructed nodes cannot be updated.

Example:
  xdmp:document-insert("/example.xml", 
    <a><b>bbb</b></a>);
  xdmp:node-insert-before(doc("/example.xml")/a/b, 
    <c>ccc</c>);
  doc("/example.xml")
 => 
  <a><c>ccc</c><b>bbb</b></a>

xdmp:node-insert-child(
$parent as node(),
$new as node()
)  as  empty()
Summary:

Adds a new last child to a node. Only element nodes and document nodes can have children. Element nodes cannot have document node children. Document nodes cannot have multiple element node children. On-the-fly constructed nodes cannot be updated. The arguments must specify individual nodes and not node sets.

Parameters:
$parent : The parent node which will have a new child node.
$new : The new child node to be inserted.

Example:
  xdmp:document-insert("/example.xml", 
    <a/>);
  xdmp:node-insert-child(doc("/example.xml")/a,
    <b>bbb</b>);
  doc("/example.xml")
 => 
  <a><b>bbb</b></a>
Example:
  xdmp:document-insert("/example.xml", <a/>);
  xdmp:node-insert-child(doc("/example.xml")/a, 
    attribute b { "bbb" });
  doc("/example.xml")
 => 
  <a b="bbb"/>

xdmp:node-replace(
$old as node(),
$new as node()
)  as  empty()
Summary:

Replaces a node.

Parameters:
$old : The old node, to be replaced.
$new : The new node.

Usage Notes:

Attribute nodes cannot be replaced by non-attribute nodes. Non-attribute nodes cannot be replaced by attribute nodes. Element nodes cannot have document node children. Document nodes cannot have multiple element node children.

Example:
  xdmp:document-insert("/example.xml", <a><b>bbb</b></a>);
  xdmp:node-replace(doc("/example.xml")/a/b, <c>ccc</c>);
  doc("/example.xml")
 =>
  <a><c>ccc</c></a>

xdmp:save(
$path as xs:string,
$node as node()
)  as  empty()
Summary:

Serializes a node and saves it as an XML text file. The node can be any node, including a document node, an element node, or a text node.

Parameters:
$path : The output file pathname. The path can be fully qualifed or relative. Relative pathnames are resolved from the directory in which MarkLogic Server is installed.
$node : The node to be serialized.

Required Privilege:

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

Example:
  xdmp:save("example.xml", $mynode)