<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.documentLoad.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.documentLoad</api:function-name><api:suggest>xdmp.documentload</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>documentload</api:suggest><api:function-link mode="xquery" fullname="xdmp:document-load">/apidoc/8.0/xdmp:document-load.xml</api:function-link><api:function mode="javascript" name="documentLoad" type="builtin" lib="xdmp" category="UpdateBuiltins" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.documentLoad"><api: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.
</api:summary><api:params><api:param name="location" type="xs:string" optional="false"><api:param-description>
    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.
  </api:param-description><api:param-name>location</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="options" type="(element()|map:map)?" optional="true"><api:param-description>
    
    <p class="javascript" xmlns="http://www.w3.org/1999/xhtml">The options object for this load operation. The 
    default value is null. This parameter can also include options in 
    <code>xdmp.httpGet</code>.</p>
    
    <p class="javascript" xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp.documentLoad</code> options 
    include:</p>
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    
    <dt class="javascript"><p>uri</p></dt>
    <dd> The URI of the document to be loaded. If omitted, then the location
    is used for the URI.</dd>
    
    <dt class="javascript"><p>permissions</p></dt>
    <dd>Security permission 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 
    <code class="javascript">xdmp.defaultPermissions()</code>. A document that 
    is created by a non-admin user (that is, by any user who does not have the
    <code>admin</code> role) must have at least one update permission,
    otherwise the creation will throw an <code>XDMP-MUSTHAVEUPDATE</code>
    exception.</dd>
    
    <dt class="javascript"><p>collections</p></dt>
    <dd>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
    
    <code class="javascript">xdmp.defaultCollections()</code>). For each 
    collection that is protected, the user must have permissions to update 
    that collection or have the <code>any-collection</code> privilege. For 
    each unprotected collection, the user must have the 
    <code>unprotected-collections</code> privilege. 
    <p class="javascript">This option is an array of collection URIs.</p></dd>
    
    <dt class="javascript"><p>quality</p></dt>
    <dd> 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.</dd>
    
    <dt class="javascript"><p>defaultNamespace</p></dt>
    <dd>(XML only) The namespace to use if there is no namespace at the root 
    node of the document.  The default value is "".</dd>
    
    <dt class="javascript"><p>repair</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.
        
        <p class="javascript">If no repair option is explicitly specified, the 
	default is <code>none</code>.</p>
        This option has no effect on binary, text or JSON documents.</dd>
    
    <dt class="javascript"><p>format</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. A value of <code>json</code>
        specifies to get the document as a JSON document, regardless of the
        URI specified.</dd>
    
    <dt class="javascript"><p>defaultLanguage</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. This option applies only to XML documents.
    If this option is not specified, then nothing is added to the root element 
    node.</dd>
    
    <dt class="javascript"><p>forests</p></dt>
    <dd>Specifies the ID of the forest in which this document is inserted.
    <span class="javascript">This can be a single string or an array of 
    strings, with each string being a forest ID. </span>. If the document 
    already exists in the database, it will remain in its existing forest. If 
    no such forest exists or if no such forest is attached to the context 
    database, an error is raised. If multiple forests
    are specified, the document is inserted into one of the specifed
    forests.  If the document already exists and the forest in which it is
    stored is set to delete-only, then you must specify the forest IDs to
    include one or more forests that allow updates, otherwise an exception is
    thrown.
    <p>
    If you have local disk failover enabled, specify the ID of the master 
    forest.  In the event of a failover, MarkLogic server will automatically 
    redirect documents to the replica forest.  Specify the ID of the replica 
    forest will result in a "forest not in database" error.
    </p>
    </dd>
    
    <dt class="javascript"><p>encoding</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 and you are using a path with an
    <code>http://</code> scheme, the encoding defaults to the
    encoding specified in the http header (if an encoding header is specified),
    otherwise it defaults to UTF-8.
    </dd>
    </dl></blockquote>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>Object?</api:param-type></api:param></api:params><api:return>null</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">When selecting documents over HTTP (where the <code>$location</code>
  parameter begins with <code>http://</code>), the response from the webserver
  is loaded into the database, regardless of what the headers returned
  from the webserver indicate.  For example, if the webserver returns a
  404 (file not found), then the response page that says "file not found"
  is loaded into the database.  If you want to examine the headers before
  loading the document, use 
  <code class="javascript">xdmp.httpGet</code> (combined with
  
  <code class="javascript">xdmp.documentInsert</code>) instead, as
  <code class="javascript">xdmp.httpGet</code>
  allows you to examine the headers returned from the HTTP server.
  </p>
</api:usage><api:privilege>
  <p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xdmp-document-load</code></p>
  <p xmlns="http://www.w3.org/1999/xhtml">If a new document is inserted, you also need the
  <code>unprotected-uri</code> privilege (only if the URI is not protected),
  the <code>any-uri</code> privilege, or an appropriate URI privilege. </p>
  <p xmlns="http://www.w3.org/1999/xhtml">If adding an unprotected collection to a document, the
  <code>unprotected-collections</code> privilege
  (<code>http://marklogic.com/xdmp/privileges/unprotected-collections</code>)
  is needed; if adding a protected collection, the user must have either
  permissions to update the collection or the
  <code>any-collection</code> privilege
  (<code>http://marklogic.com/xdmp/privileges/any-collection</code>).
  </p>
</api:privilege><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
declareUpdate();
xdmp.documentLoad("c:\\myFile.json",
    {
      "uri" : "/documents/myFile.json",
      "permissions" : xdmp.defaultPermissions()
    })

=&gt; Loads the document with a URI "/documents/myFile.json".


</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
declareUpdate();
xdmp.documentLoad("http://myCompany.com/file.json",
    {
      "uri" : "/documents/myFile.json",
      "permissions" : xdmp.defaultPermissions(),
      "format" : "json",
      "authentication" : {
        "username" : "user",
        "password" : "pass"
      }
    })

=&gt; Loads the document with a URI "/documents/myFile.json"
   from the server http://myCompany.com, sending the
   credentials user/pass. The document is loaded as JSON.


</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
declareUpdate();
xdmp.documentLoad("c:\myFile.json",
    {
      "uri" : "/documents/myFile.json",
      "permissions" : xdmp.defaultPermissions(),
      "collections" : ["myCollection1", "myCollection2"],
      "forests" : xdmp.forest("myForest")
    })

=&gt; Loads the document with a URI "/documents/myFile.json", adding the
   document to the "myCollection1" and "myCollection2" collections,
   and loading the document into the forest named "myForest".


</pre></api:example></api:function></api:function-page>