4

I wrote an XQuery expression that has a large result of about 50MB and takes a couple of hours to compute. I execute it in the BaseX GUI, but this is a little inconvenient: it crops the result to a result window, which I then have to save. At this time, BaseX becomes unresponsive and may crash.

Is there a way to directly write the result to a file?

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
wvdz
  • 16,251
  • 4
  • 53
  • 90

1 Answers1

3

Have a look at BaseX' file module, which provides broad functionality to read and write from files and traverse the file system.

For you, file:write($path as xs:string, $items as item()*) as empty-sequence() will be of special interest, which allows to write an element sequence to a file. For example:

file:write(
  '/tmp/output.xml',
  <root>{
    for $i in 1 to 1000000
    return <some-large-amount-of-data />
  }</root>
)

If your output isn't well-formed XML, consider the file:write-binary, file:write-text and file:write-text-lines functions.

Yet another alternative might be writing to documents in the database instead of files. db:add and db:create from the database module can be used to add the computed results to the current or a new database.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96