Loading TOC...

xdmp.documentGet

xdmp.documentGet(
   $location as String,
   [$options as Object?]
) as Sequence

Summary

Returns the document in the file specified by $location.

Parameters
$location The location of the input document. If the scheme of the location is HTTP (that is, if the string starts with "http://"), then the document is requested over HTTP. 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.
$options The options object for getting this document. The default value is null. This parameter can also include options in xdmp.httpGet

The xdmp.documentGet options include:

defaultNamespace

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.

If no repair option is explicitly specified, the default is none.

This option has no effect on binary, text or JSON 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. A value of json specifies to get the document as a JSON document, regardless of the URI specified.

defaultLanguage

The language to specify in an xml:lang attribute on the root element node if the root element node does not already have an xml:lang attribute. This option applies only to XML documents. If this option is not specified, then nothing is added to the root element node.

encoding

Specifies the encoding to use when reading the document into MarkLogic Server. Supported values include UTF-8, ISO-8859-1, as well as many other popular encodings. See the Search Developer's Guide 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 encoding option will be matched to an encoding name according to the Unicode Charset Alias Matching rules (http://www.unicode.org/reports/tr22/#Charset_Alias_Matching). An automatic encoding detector will be used if the value auto 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, xdmp.httpGet), otherwise it defaults to UTF-8; any encoding http headers are ignored if there is any value specified for the encoding option.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-document-get

Usage Notes

If no format is specified in $options, and the document is from an HTTP server, the format is specified by the document content type from the HTTP response. If no format is specified in $options, and the document is from the filesystem, the format is specified by the document content type from the filename extension. The mimetype extensions and corresponding content types are set in the Admin Interface.

When the document is from an HTTP server, xdmp.documentGet will always return the response from the HTTP server, even if it is an error response such as 404 or 500. If you want to be able to examine the response header in your application, use the xdmp.httpGet instead, which returns both the response header and the response.

Example

  xdmp.documentGet("myDocument.json")
  => A Sequence containg the JSON document 
        in myDocument.json, for example, {"foo" : "bar"};

Example

  fn.head(xdmp.documentGet("http://myCompany.com/file.json",
       {
         "format" : "json",
         "authentication" : {
           "username" : "user",
           "password" : "pass"
         }
       })).root;
  => gets a JSON document named file.json, sending the
     authentication credentials user/pass to the
     http://myCompany.com server.  Note the fn.head 
     gets you to the first item in the Sequence, and the 
     .root gets you past the document node into the json object.

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy