Create and deliver personalized experiences across digital properties at scale
Build engaging websites with intuitive web content management
Leverage a complete UI toolbox for web, mobile and desktop development
Build, protect and deploy apps across any platform and mobile device
Build mobile apps for iOS, Android and Windows Phone
Rapidly develop, manage and deploy business apps, delivered as SaaS in the cloud
Automate UI, load and performance testing for web, desktop and mobile
Optimize data integration with high-performance connectivity
Automate decision processes with a no-code business rules engine
Globally scale websites with innovative content management and infrastructure approaches
Content-focused web and mobile solution for empowering marketers
Faster, tailored mobile experiences for any device and data source
UX and app modernization to powerfully navigate today's digital landscape
Fuel agility with ever-ready applications, built in the cloud
The latest version of the DataDirect Data Integration Suiteincludes 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.
[cc lang="xquery"]ddtek:serialize-to-url(1, "zip:file:///C:/example.zip!/example1.xml?auto-create=yes", ""),
ddtek:serialize-to-url(2, "zip:file:///C:/example.zip!/dir1/example2.xml", ""),
ddtek:serialize-to-url(3, "zip:file:///C:/example.zip!/dir2/example3.xml", "")[/cc]
Note the first invocation of ddtek:serialize-to-url() includes the auto-create=yes option, making sure a new ZIP file is created. The following two invocations are adding more documents to the ZIP. The zip URL consists basically out of two parts. First the location of the ZIP file is specified. And second, after the exclamation mark, the location where the file needs to be added in the ZIP file.
Executing the above XQuery, results in a ZIP file as follows.
Let's now have a look at a more concrete example. In Create (EDI) messages out of your database we explained how easy it is to create EDI messages based on your data in a relational database. But assume now each of these EDI messages should be compressed in a ZIP file. Not much is changed compared to what we know already.
The next example creates for each supplier with orders for today, a ZIP file named after the supplier. Each of the ZIP files contain a single EANCOM ORDERS message. Note that only the "let $url" clause is specific to the creation of the ZIP files.
[cc lang="xquery"]for $supplier in collection("SUPPLIERS")/SUPPLIERS
let $orders := collection("ORDERS")/ORDERS
[SUP_ID = $supplier/ID and
ORDER_DATE = current-date()]
let $url := concat("zip:file:///C:/output/",
let $edi := (: this message is incomplete :)
for $order at $lineitem in $orders
ddtek:serialize-to-url($edi, $url, "method=EDI")
Back to our question, "Why would you want to create ZIP files in XQuery?".Yes there is more than the type of use cases shown above. Remember a rather old post XQuery your office documents. Both Office Open XML and OpenDocument Format are based on the ZIP standard. The ability to create ZIP files with DataDirect XQuery, opens the world of creating office documents. In my next post I'll show how to create Microsoft Excel spreadsheets in a few lines of XQuery. Followed with demonstrating the equivalent for OpenOffice.
View all posts from Marc Van Cappellen on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.