-
Notifications
You must be signed in to change notification settings - Fork 80
Exporting data
New in 3.3.0, ml-gradle provides a task named "mlExportToFile" for exporting data from MarkLogic to a single file:
gradle mlExportToFile -PwhereCollections=example
This task is similar to the other DMSDK Tasks in that a "where" property is required to specify the documents to export. "whereCollections", "whereUriPattern", and "whereUrisQuery" are the current supported properties, e.g.:
gradle mlExportToFile -PwhereUriPattern=*.xml
gradle mlExportToFile -PwhereUrisQuery="cts:element-value-query(xs:QName('hello'), 'world')"
By default, this will write to a file "build/export.xml". You can easily change this:
gradle mlExportToFile -PexportPath=path/to/file.xml -PwhereCollections=example
This export capability is simply wrapping existing DMSDK functionality, specifically the ExportToWriterListener class. So you can utilize some of the properties on that class, e.g.:
gradle mlExportToFile -PrecordPrefix="<wrapper>" -PrecordSuffix="</wrapper>" -PwhereCollections=example
Similar to recordPrefix and recordSuffix, you can also specify content to be written to the beginning and end of the file via filePrefix and fileSuffix:
gradle mlExportToFile -PwhereCollections=example -PfilePrefix="<results>" -PfileSuffix="</results>"
With mlExportToFile, you can reference a REST API transform, which enables exporting data to CSV - i.e. write a transform that converts a document to the exact CSV that you want (and of course you can load that transform with ml-gradle):
gradle mlExportToFile -Ptransform=my-csv-transform -PwhereCollections=example
You can use ml-gradle to stub out that transform first:
gradle mlCreateTransform -PtransformName=my-csv-transform -PtransformType=sjs|xqy|xsl
Of course, the REST API transform can produce any content that you want.