-
Notifications
You must be signed in to change notification settings - Fork 77
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 tasks requires that a "where" property, as documented on the DMSDK Tasks page, specify which 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, particularly 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:
gradle mlExportToFile -PwhereCollections=example -PfilePrefix="<results>" -PfileSuffix="</results>"
And 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