The latest version of the DataDirect Data Integration Suite includes the ability to create and update ZIP files, straight from within XQuery.
Why would you want to create ZIP files with XQuery? Before answering the question, let’s first take a “how to look” using DataDirect XQuery, part of the Data Integration Suite. We have talked about the ddtek:serialize-to-url() function before in this blog. My colleague Minollo did for example in How to split a large XML document in many smaller ones? or check out my series XQuery generating multiple XML documents. So we know how to use XQuery and create for example XML documents or EDI messages. And now we can also create ZIP files. In the next example we create a ZIP file and add three XML documents to it.1 2 3 | ddtek:serialize-to-url(<example>1</example>, "zip:file:///C:/example.zip!/example1.xml?auto-create=yes", ""), ddtek:serialize-to-url(<example>2</example>, "zip:file:///C:/example.zip!/dir1/example2.xml", ""), ddtek:serialize-to-url(<example>3</example>, "zip:file:///C:/example.zip!/dir2/example3.xml", "") |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | for $supplier in collection("SUPPLIERS")/SUPPLIERS let $orders := collection("ORDERS")/ORDERS [SUP_ID = $supplier/ID and ORDER_DATE = current-date()] where $orders return let $url := concat("zip:file:///C:/output/", $supplier/NAME, ".zip!/", $supplier/NAME, "edi?auto-create=yes") let $edi := (: this message is incomplete :) <edifact> <unb> <unb01> <unb0101>UNOA</unb0101> <unb0102>4</unb0102> </unb01> <unb02> <unb0201>MYBOOKSHOP</unb0201> <unb0202>666</unb0202> </unb02> <unb03> <unb0301>{ $supplier/NAME/text() }</unb0301> <unb0302>{ $supplier/BUSINESS_ID/text() }</unb0302> </unb03> <unb05>6002</unb05> </unb> <orders>{ for $order at $lineitem in $orders return <group_28> <lin> <lin01>{$lineitem}</lin01> <lin02>1</lin02> <lin03> <lin0301>{ $order/ISBN/text() }</lin0301> <lin0302>IB</lin0302> </lin03> </lin> <qty> <qty01> <qty0101>1</qty0101> <qty0102>{ $order/QUANTITY/text() }</qty0102> </qty01> </qty> </group_28> }</orders> </edifact> return ddtek:serialize-to-url($edi, $url, "method=EDI") |
