Loading TOC...

MarkLogic 12 EA 2 Product Documentation
xdmp:zip-create

xdmp:zip-create(
   $manifest as node(),
   $nodes as node()+
) as binary()

Summary

Create a zip file from a list of nodes.

Parameters
$manifest The zip manifest, which must be in the xdmp:zip namespace and conform to the zip.xsd schema, located in the marklogic-dir/Schemas directory. The manifest has the following basic form:
    <parts xmlns="xdmp:zip">
      <part last-modified="2009-03-23T19:30:32">path1</part>
      <part>path2</part>
      ...more parts
    </parts>   
Any of the size or encrypted attributes in the manifest are ignored for xdmp:zip-create. Attributes other than uncompressed-size, compressed-size, encrypted, and last-modified will throw an error. If the last-modified attribute is specified, that date and time will be set for the part. Otherwise, if the node for the part comes from a database that tracks the last modified time of a document, that date and time will be used. The current date and time will be used if no other value is available. Due to a limitation in the zip file format, the time has a granularity of two seconds (e.g. 10:22:33 becomes 10:22:32).
$nodes The nodes that you want to zip up. The nodes correspond to part elements in the manifest, where the first node corresponds to the first part element specified, the second node to the second part element, and so on. Specifying a different number of <part> elements than nodes will result in an error.

Usage Notes

While you can create a zip file of encrypted content, xdmp:zip-create does not have the capability to encrypt the content to be zipped.

The <part> elements in the manifest should contain relative paths so the zip file can be unpacked into its own directory; do not start the path with a forward slash or a backslash.

To support creating Open Container Format archives for the EPUB format, xdmp:zip-create will not compress the first part if it is named "mimetype".

Example

let $zip := xdmp:zip-create(
               <parts xmlns="xdmp:zip">
                 <part>mydoc.xml</part>
                 <part>mypicture.jpg</part>
                </parts>,
                (doc("/mydoc.xml"), doc("/mypicture.jpg")))
return
xdmp:save("c:/tmp/myzip.zip", $zip)

(: Creates a zip archive that includes the documents "/mydoc.xml"
 : and "/mypicture.jpg", then saves that to the filesystem. :)

Example

(: the "mimetype" file will not be compressed, so as to support
   the EPUB format :)
let $zip := xdmp:zip-create(
               <parts xmlns="xdmp:zip">
                 <part>mimetype</part>
                 <part>META-INF/container.xml</part>
                 <part>OEBPS/content.opf</part>
                 <part>OEBPS/content.pdf</part>
                </parts>,
                (document { "application/epub+zip" },
                 doc("/my-doc/container.xml"),
                 doc("/my-doc/content.opf"),
                 doc("/my-doc/content.pdf")
                 ))
return
xdmp:save("c:/tmp/mydoc.epub", $zip)

(: Creates a zip archive that meets the OCF specification,
 : then saves that to the filesystem. :)

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