Hi George,
The BaseX-specific 'newline' option does the job [1]:
declare option output:newline '\r\n'; csv:serialize( <csv> <record> <entry>A</entry> <entry>B</entry> </record> <record> <entry>C</entry> <entry>D</entry> </record> </csv> )
Please note that the newline option cannot be specified in the function call, as (with Linux) '\r\n' would get normalized to '\n' again in the top-level result serialization.
Here is another example that directly writes the result to a file (for the 'xquery' option, BaseX 9.0 beta is required):
file:write( file:base-dir() || 'result.csv', map { 'records': ([ 'A', 'B' ], [ 'C', 'D' ]) }, map { 'method': 'csv', 'newline': '\r\n', 'csv': map { 'format': 'xquery' } } )
We added the newline option, because there is no official feature for that. But…
• You can use item-separator as a delimiter for multiple items that need to be serialized (I saw you already discovered this option).
• You can also compose a string with CRs and write it to a file as single text:
file:write-text( file:base-dir() || 'result.csv', string-join( ('A,B', 'C,D'), '
' ) )
And I assume there are various other solutions (but I assume each additional solution leads to more confusion…).
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Serialization
On Wed, Nov 29, 2017 at 11:44 AM, George Sofianos gsf.greece@gmail.com wrote:
Hi,
What I'm trying to do is serialize a CSV with CRLF newlines in Linux using BaseX. It's not really important since my CSV parser supports both newlines, but maybe this discussion can help me understand how BaseX serialization works, or create an improvement for BaseX.
I'm running BaseX GUI (latest snapshot). I have a sequence of strings that are CSV. I'm using fn:serialize with an item-separator of xml entity 
 I'm then returning this output as a result of the script. This gives me about 200 lines of CSV. Copy pasting these lines into an editor, or using the Save button from the GUI, saves these values with an LF newline character.
The RFC [2] for CSV files recommends a CRLF character for CSV, so it would be nice if I can serialize this from BaseX directly. I tried some options from the wiki [1] but had no luck. File module also uses a system specific newline character. [3] Maybe this is something that could be a part of CSV serialization issue [4] , or maybe it is already possible to achieve this somehow.
Thanks,
George
[1|http://docs.basex.org/wiki/Serialization] [2|https://tools.ietf.org/html/rfc4180#section-2] [3|http://docs.basex.org/wiki/File_Module#file:write-text-lines] [4|https://github.com/BaseXdb/basex/issues/1518]