xdmp.documentGet( location as String, [options as Object?] ) as Sequence
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 qualified or relative. Relative pathnames are resolved from the directory in which MarkLogic Server is installed. |
options |
Options with which to customize this operation.
This function supports the following options, as well as options from
xdmp.httpGet when
retrieving content via an HTTP request.
|
http://marklogic.com/xdmp/privileges/xdmp-document-get
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.
xdmp.documentGet("myDocument.json") => A Sequence containing the JSON document in myDocument.json, for example, {"foo" : "bar"};
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.
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.