xdmp:zip-get( $zipfile as binary(), $name as xs:string, [$options as (element()|map:map)?] ) as node()+
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.
You can specify options as either an XML element
in the "xdmp:zip-get" namespace, or as a map:map . The
options names below are XML element localnames. When using a map,
replace the hyphens with camel casing. For example, "an-option"
becomes "anOption" when used as a map:map key.
This function supports the following options:
|
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
node
(see the second example below).
xdmp:zip-get(doc("/zip/tmp.zip"), "files/myxmlfile.xml") => the "files/myxmlfile.xml" node from the "/zip/tmp.zip" zip file
xdmp:zip-get(doc("/zip/tmp.zip"), "myDocument.xmlfile", <options xmlns="xdmp:zip-get"> <format>xml</format> </options>) => the "myDocument.xmlfile" node from the "/zip/tmp.zip" zip file, as an XML document
(: unzip all of the files in the zip archive :) xquery version "1.0-ml"; declare namespace zip="xdmp:zip"; for $x in xdmp:zip-manifest(doc("/zip/tmp.zip"))//zip:part/text() return xdmp:zip-get(doc("/zip/tmp.zip"), $x) => a sequence of all of the unzipped nodes in the "/zip/tmp.zip" zip file