<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.documentGet.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.documentGet</api:function-name><api:suggest>xdmp.documentget</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>documentget</api:suggest><api:function-link mode="xquery" fullname="xdmp:document-get">/apidoc/8.0/xdmp:document-get.xml</api:function-link><api:function mode="javascript" name="documentGet" type="builtin" lib="xdmp" category="Extension" subcategory="MarkLogic Server" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.documentGet"><api:summary>
  Returns the document in the file specified by $location.
</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>
    
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">The options object for getting this document.
    The default value is null. This parameter can also include
    options in <a href="./xdmp.httpGet"><code>xdmp.httpGet</code></a></span>
    
    <p class="javascript" xmlns="http://www.w3.org/1999/xhtml">The <code>xdmp.documentGet</code> options include:</p>
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    
    <dt class="javascript"><p>defaultNamespace</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 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>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, the encoding defaults to the
    encoding specified in the http header (if using with one of the http
    functions, for example, 
    <code class="javascript">xdmp.httpGet</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>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>Object?</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api: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">When the document is from an HTTP server,
  
  <code class="javascript">xdmp.documentGet</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 class="javascript" href="./xdmp.httpGet"><code>xdmp.httpGet</code></a> instead,
  which returns both the response header and the response.</p>
</api:usage><api:privilege>
   <code xmlns="http://www.w3.org/1999/xhtml">http://marklogic.com/xdmp/privileges/xdmp-document-get</code>
</api:privilege><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp.documentGet("myDocument.json")
  =&gt; A ValueIterator containg the JSON document 
        in myDocument.json, for example, {"foo" : "bar"};
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp.documentGet("http://myCompany.com/file.json",
       {
         "format" : "json",
         "authentication" : {
           "username" : "user",
           "password" : "pass"
         }
       }).next().value.root;
  =&gt; gets a JSON document named file.json, sending the
     authentication credentials user/pass to the
     http://myCompany.com server.  Note the .next().value 
     gets you into the ValueIterator, and the .root gets 
     you past the document node into the json object.

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