databaserestxquerybasexxml-declaration

including XML declaration in BaseX export called over REST


I have been using BaseX and REST for a few months now to play around with some XML files. Up to this point I have been exporting my files using the query:

db:export(',char(39),dbName,char(39),',',char(34),'path',char(34),')

If this is confusing, it is just because I am showing how it is constructed, the actual call looks like:

http://localhost:8984/rest?query=db%3Aexport%28%27dbName%27%2C%22C%3A%5CUsers%5Cdak52%5CDocuments%5Cfolder%22%29

Anyways, this works just fine, but I want to include the XML declaration in my output. I have tried setting the omit-xml-declaration option to "no" but I guess I am not doing it correctly. It works fine when I try to export from the BaseX GUI specifying that option, but I want to do it all via REST, and that is where I am having problems. Below is my query with the option included.

http://localhost:8984/rest?query=db%3Aexport%28%27dbName%27%2C%22C%3A%5CUsers%5Cdak52%5CDocuments%5Cfolder%22%29&omit-xml-declaration=no

This runs and generates output, but this output does not include my xml declaration.


Solution

  • Output Serialization Options

    Generally, there are two options for declaring the output serialization parameters (I simplified the query):

    Export Serialization Options

    The problem is these both set the output serialization options. You need to change the export options instead, as described in the documentation. For a query

    db:export("foo", "/tmp", map { 'omit-xml-declaration': 'no' })
    

    use the REST call

    http://localhost:8984/rest?query=db:export(%22foo%22,%20%22/tmp%22,%20map%20{%20%27omit-xml-declaration%27:%20%27no%27%20})