Loading TOC...

MarkLogic Server 11.0 Product Documentation
xdmp.zipGet

xdmp.zipGet(
   zipfile as binary(),
   name as String,
   [options as Object?]
) as Sequence

Summary

Get a named file from a zip document. Unzips and returns the file in memory as a document node (for XML and JSON formats), a text node (for text formats), or a binary node (for binary). The format is determined either by the mimetype from the file name or by the format option.

Parameters
zipfile The zip file.
name The path to the zip file as shown in the zip manifest.
options Options with which to customize this operation. Specify your options as a JavaScript object, with the option names as the object property names. This function supports the following options:

defaultNamespace

(XML only) 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 implicitly specified by the

language of the caller. From JavaScript, 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

(XML only) 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. If defaultLanguage 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. The value must either be "auto" or match an encoding name according to the Unicode Charset Alias Matching rules (http://www.unicode.org/reports/tr22/#Charset_Alias_Matching). When the value is "auto", MarkLogic guesses the encoding from the document content. For a list of character set encodings by language, see Collations and Character Sets By Language in the Search Developer's Guide. If you do not set this option, MarkLogic uses the encoding specified in the HTTP headers, if present. If you do not set this option and no encoding is available from HTTP headers, the encoding defaults to UTF-8. For more details, see Character Encoding in the Search Developer's Guide.

Usage Notes

The name of the document you are extracting will determine the default format in which the document is extracted, based on the mimetype settings. For example, if you are extracting a document with the name myDocument.xmlfile, it will by default extract that document as a text document (because it is an unknown mimetype, and unknown mimetypes default to text format). If you know this is an XML document, then specify a format of xml in the options object (see the second example below).

Example

xdmp.zipGet(doc("/zip/tmp.zip"), "files/myxmlfile.xml")

=> the "files/myxmlfile.xml" node from the "/zip/tmp.zip" zip file

Example

xdmp.zipGet(fn.doc("/zip/tmp.zip"), "myDocument.jsonfile",
    {
      "format" : "json"
    })
=> the "myDocument.jsonfile" node from the "/zip/tmp.zip"
   zip file, as a JSON document

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.