Editing ZIP Packages with XForms

Binary formats are declining now for ZIP packages and XML documents are frequent in them. Microsoft Open XML (for Word, Excel, PowerPoint), Open Document Format (for OpenOffice, LibreOffice) and EPUB are all using ZIP packages.

Any ZIP package is a flat collection of files and, eventually, folders. Files can refer to not-explicitly-defined folders by just mentioned them in their names. For example, “xl/worksheets/sheet1.xml” is a valid file name and no declaration is required for “xl” nor “worksheets” folders.

It is easy to extend XForms to allow ZIP packages editing:

First of all, mime types can be used to distinguish them. The default one is “application/zip” but there are many others such as “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet” for Excel 2007. So, a mime type value can be used in a submission to indicate that a ZIP package will be sent or received.

An instance with such a mediatype can be initialized with @src but, if it is not possible, it has to be created with a temporary document. It means that when replacing an instance at the end of a submission, the mediatype is changed accordingly.

But, to access data in a ZIP package, a file name has to be provided. It implies that the instance() is to be called and that there must be an extra optional parameter for this file name. Adding a second parameter for the specific mediatype of the file might be helpful too. For example, to access the value of the B3 cell, the XPath expression will be: instance(‘myworkbook’,’xl/worksheets/sheet1.xml’)/ss:sheetData/ss:row[@r = 3]/ss:c[@r = ‘B3′]/ss:is/ss:t

This is enough for extracting XML data from any ZIP package and modify it before submitting the modified ZIP package.

This has been experimented in XSLTForms with well-known zip_inflate and zip_deflate Javascript functions written by Masanao Izumo (http://www.onicos.com/staff/iz/amuse/javascript/expert/). For example, a form written with XSLTForms can be initialized with data coming from an Office file, it can modify it directly in the browser without the Microsoft Office Suite being installed locally.

For better Excel editing experience, XSLTForms uses XSLT to convert any shared string in an Excel sheet into an inline string. It allows to directly access and modify cell content in the same file. If formulas might have to be recalculated in the spreadsheets, instead of having to press Ctrl+Alt+F9, the simplest way is to add the attribute fullCalcOnLoad to the calcPr element in the workbook.xml document with “1” as value (this can easily be done with an insert action).

It is also easier to initialize the cells to be set with a dummy value because empty cells are not present in the XML serialization. A work instance with bindings to fill the Excel sheet is also a light way to design the form.

Full ZIP packages management would require to define extra actions to remove/add a file. But it is already possible to create a template ZIP package with the exact number of required files (for Excel, each sheet is represented a distinct file, itself being listed in other files).

Here is the example for this: http://www.agencexml.com/xsltforms/Workbook-Editor.xml

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Before you comment here, note that this forum is moderated and your IP address is sent to Akismet, the plugin we use to mitigate spam comments.