qt4cg / qtspecs

QT4 specifications
https://qt4cg.org/
Other
28 stars 15 forks source link

Serialize functions: consistency #760

Open ChristianGruen opened 11 months ago

ChristianGruen commented 11 months ago

We should be more ambitious about ensuring consistency when serializing data back to its original representation, and how to achieve it. This is the status quo:

Format Serialize Function Parse Function
XML fn:serialize($input) fn:parse-xml
JSON fn:serialize($input, map { 'method': 'json' }) fn:parse-json
JSON fn:xml-to-json($input) fn:json-to-xml
XHTML fn:serialize($input, map { 'method': 'xhtml' }) fn:parse-html
HTML fn:serialize($input, map { 'method': 'html' }) fn:parse-html
CSV still missing fn:parse-csv and variants

In BaseX, the XML created by fn:json-to-xml can already be serialized back to JSON as follows (related: #759):

serialize(
  <map xmlns="http://www.w3.org/2005/xpath-functions">
    <number key="A">1</number>
  </map>,
  map { 'method': 'json', 'json': map { 'format': 'basic' }
})

For CSV, we’ve introduced a CSV serialization method that supports all CSV flavors we support (see CSV Module for more details):

serialize(
  <map xmlns="http://www.w3.org/2005/xpath-functions">
    <number key="A">1</number>
  </map>,
  map { 'method': 'csv', 'csv': map { 'format': 'direct' }
})

Related (parse functions): #748

ndw commented 3 months ago

What is the actual proposal?

ChristianGruen commented 3 months ago

Greetings to Prague… The proposal could be twofold:

  1. introduce a csv serialization method;
  2. add a serialization parameter for the existing json method to serialize the result of fn:json-to-xml back to JSON.