Changes

Jump to navigation Jump to search
484 bytes removed ,  27 February
no edit summary
This [[Module Library|XQuery Module]] contains functions to handle ZIP archives. The contents of ZIP files can be extracted and listed, and new archives can be created. The module is based on the [http://expath.org/spec/zip EXPath ZIP Module]. It will soon be replaced by another [http://spex.basex.org/index.php?title=ZIP_Module Please note that the ZIP Module]module is not being actively maintained but is still distributed for compatibility with older applicationsAn additional page in this Wiki demonstrates how to We recommend you use the [[ZIP Archive Module: Word Documents|modify Word documents]] with the ZIP modulewherever possible.
=Conventions=
All functions in this module are assigned to the {{Code|<code><nowiki>http://expath.org/ns/zip}} </nowiki></code> namespace, which is statically bound to the {{Code|zip}} prefix.<br/>All errors are assigned to the {{Code|<code><nowiki>http://expath.org/ns/error}} </nowiki></code> namespace, which is statically bound to the {{Code|exerrexperr}} prefix.
=Functions=
==zip:binary-entry==
{|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|zip:binary-entry|$uri as xs:string, $path as xs:string|xs:base64Binary}}
|-
|-
| '''Errors'''
|{{Error|FOZP0001ZIP0001|XQuery Errors#ZIP Functions Errors}} the specified path does not exist.<br />{{Error|FOZP0003ZIP0003|XQuery Errors#ZIP Functions Errors}} the operation fails for some other reason.
|}
==zip:text-entry==
{|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|zip:text-entry|$uri as xs:string, $path as xs:string|xs:string}}<br />{{Func|zip:text-entry|$uri as xs:string, $path as xs:string, $encoding as xs:string|xs:string}}
|-
|-
| '''Errors'''
|{{Error|FOZP0001ZIP0001|XQuery Errors#ZIP Functions Errors}} the specified path does not exist.<br />{{Error|FOZP0003ZIP0003|XQuery Errors#ZIP Functions Errors}} the operation fails for some other reason.
|}
==zip:xml-entry==
{|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|zip:xml-entry|$uri as xs:string, $path as xs:string|document-node()}}<br />
|-
|-
| '''Errors'''
|{{Error|FODC0006ZIP0001|XQuery Errors#ZIP Functions Errors}} the addressed file is not well-formed.<br />{{Error|FOZP0001|XQuery Errors#ZIP Functions Errors}} the specified path does not exist.<br />{{Error|FOZP0003ZIP0003|XQuery Errors#ZIP Functions Errors}} the operation fails for some other reason.
|}
==zip:html-entry==
{|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|zip:html-entry|$uri as xs:string, $path as xs:string|document-node()}}<br />
|-
| '''Summary'''
|Extracts the HTML file at {{Code|$path}} within the ZIP file located at {{Code|$uri}} and returns it as a document node. The file is converted to XML first if [http://home.ccil.org/~cowan/XML/tagsoup/ [Parsers#HTML_Parser|Tagsoup]] is found in the classpath.
|-
| '''Errors'''
|{{Error|FODC0006ZIP0001|XQuery Errors#ZIP Functions Errors}} the addressed file is not well-formed, or cannot be converted to correct XML.<br />{{Error|FOZP0001|XQuery Errors#ZIP Functions Errors}} the specified path does not exist.<br />{{Error|FOZP0003ZIP0003|XQuery Errors#ZIP Functions Errors}} the operation fails for some other reason.
|}
==zip:entries==
{|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|zip:entries|$uri as xs:string|element(zip:file)}}<br />
|-
|-
| '''Errors'''
|{{Error|FOZP0001ZIP0001|XQuery Errors#ZIP Functions Errors}} the specified path does not exist.<br />{{Error|FOZP0003ZIP0003|XQuery Errors#ZIP Functions Errors}} the operation fails for some other reason.
|-
| '''Examples'''
|* If the ZIP archive {{Code|archive.zip}} is empty, {{Code|zip:entries('archive.zip')}} returns {{Code|:<syntaxhighlight lang="xml"><zip:file xmlns:zip="http://expath.org/ns/zip" href="archive.zip"/>}}.</syntaxhighlight>
|}
==zip:zip-file==
{|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|zip:zip-file|$zip as element(zip:file)|empty-sequence()}}<br />
|-
|-
| '''Errors'''
|{{Error|FOZP0001ZIP0001|XQuery Errors#ZIP Functions Errors}} an addressed file does not exist.<br />{{Error|FOZP0002ZIP0002|XQuery Errors#ZIP Functions Errors}} entries in the ZIP archive description are unknown, missing, or invalid.<br />{{Error|FOZP0003ZIP0003|XQuery Errors#ZIP Functions Errors}} the operation fails for some other reason.<br />{{Error|Serialization Errors|XQuery Errors#Serialization Errors}} an inlined XML fragment cannot be successfully serialized.
|-
| '''Examples'''
|* The following function creates a file {{Code|archive.zip}} with the file {{Code|file.txt}} inside:<pre classsyntaxhighlight lang="brush:xquery">
zip:zip-file(
<file xmlns="http://expath.org/ns/zip" href="archive.zip">
<entry src="file.txt"/>
</file>)
</presyntaxhighlight>* The following function creates a file {{Code|archive.zip}}. It contains one file {{Code|readme}} with the content "{{Code|thanks}}":<pre classsyntaxhighlight lang="brush:xquery">
zip:zip-file(
<file xmlns="http://expath.org/ns/zip" href="archive.zip">
<entry name="readme">thanks</entry>
</file>)
</presyntaxhighlight>
|}
==zip:update-entries==
{|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|zip:update-entries|$zip as element(zip:file), $output as xs:string|empty-sequence()}}<br />
|-
|-
| '''Errors'''
|{{Error|FOZP0001ZIP0001|XQuery Errors#ZIP Functions Errors}} an addressed file does not exist.<br />{{Error|FOZP0002ZIP0002|XQuery Errors#ZIP Functions Errors}} entries in the ZIP archive description are unknown, missing, or invalid.<br />{{Error|FOZP0003ZIP0003|XQuery Errors#ZIP Functions Errors}} the operation fails for some other reason.<br />{{Error|Serialization Errors|XQuery Errors#Serialization Errors}} an inlined XML fragment cannot be successfully serialized.
|-
| '''Examples'''
|* The following function creates a copy {{Code|new.zip}} of the existing {{Code|archive.zip}} file:<pre classsyntaxhighlight lang="brush:xquery">
zip:update-entries(zip:entries('archive.zip'), 'new.zip')
</presyntaxhighlight>* The following function deletes all PNG files from {{Code|archive.zip}}:<pre classsyntaxhighlight lang="brush:xquery">
declare namespace zip = "http://expath.org/ns/zip";
copy $doc := zip:entries('archive.zip')
modify delete node $doc//zip:entry[ends-with(lower-case(@name), '.png')]
return zip:update-entries($doc, 'archive.zip')
</presyntaxhighlight>
|}
[[Category:XQuery]]=Errors= {| class="wikitable" width="100%"! width="110"|Code|Description|-|{{Code|ZIP0001}}|A specified path does not exist.|-|{{Code|ZIP0002}}|Entries in the ZIP archive description are unknown, missing, or invalid.|-|{{Code|ZIP0003}}|An operation fails for some other reason.|}
Bureaucrats, editor, reviewer, Administrators
12,024

edits

Navigation menu