Learn XQuery |
Home:Learn XQuery:XQuery Tutorial:XML Output XML Output: Generating Multiple XML documents Using XQueryA common requirement of DataDirect XQuery customers is the ability to generate multiple XML output files. Imagine a directory with XML files, each of which needs to be transformed and result in a new XML document. Wouldn't it be great to query the complete directory and generate the corresponding results, all from a single XQuery? No need to glue multiple queries together, do external scripting, or write Java or any other proprietary code. Simply a single XQuery! Generating Multiple XML Output FilesThis use case is not new. And not surprising, people are generating multiple XML output files in XSLT since a long time using the The good news is that DataDirect XQuery 3.1 adds the following out-of-the-box support to serialize query results in a file. ddtek:serialize-to-url(
XQuery Output ExampleThe following XML output example creates a output.xml file in the c:\results directory, let $item := <message>XQuery rocks!</message> As you see there is no need at all to write any Java code, this can be executed from within your favorite XQuery editor or using the DataDirect XQuery command line utility. As a URL specifies the output location, you can for example easily upload the result to an FTP server, let $item := <message>XQuery rocks!</message> Finally, the serialization of the results can be tweaked. Here we encode the XML output as UTF-16 and specify to include an XML declaration, let $item := <message>XQuery rocks!</message> Let's look at a more concrete example, where all XML documents are copied from one directory to another. in this query we use DataDirect XQuery's capability to query a complete directory through declare function local:get-file-name($document-uri as xs:string){
Assuming this XQuery is saved as java -jar C:\ddxq\lib\ddxq.jar C:\xquery\copy-document.xq How to Generate Multiple XML Output Files with XQueryIn this tutorial you learned how easy it is to generate multiple output documents from a single XQuery application. To try it out yourself, download a free trial of DataDirect XQuery today. |
Stay Informed!XQuery is one of the hottest XML technologies being developed today. Stay informed with vital news about standards, tools, and trends by signing up for the DataDirect XQuery® newsletter. |





