joewiz
10/30/2013 - 10:02 PM

Save a collection of XML documents from eXist-db onto the file system, with XQuery

Save a collection of XML documents from eXist-db onto the file system, with XQuery

xquery version "3.0";

let $file-system-target-base-directory := 
    (: Mac :)
    (: '/Users/Joe/workspace/paho-trunk' :)
    (: Windows :)
    'C:\Users\wicentowskijc\oxygensvn\paho-trunk'
let $source-collection := '/db/cms/apps/tei-content/data/short-history'
for $doc in collection($source-collection)
let $target := 
    (: Put the files into a corresponding directory in the file system :)
    concat($file-system-target-base-directory, replace(base-uri($doc), '/', '\\'))
return 
    file:serialize($doc, $target, ("omit-xml-declaration=yes", "indent=yes"))