Serialize csv xquery map
Tuesday, 29 May 2018 · 3 messages
AB
Andy Bunce29 May 2018 16:43 #
The xqueryformat of CSV records as a sequence of arrays [1] is very useful when parsing
but there seems to be no easy way to serialize from this format. Is this correct?
map {
"records": ["Huber", "Sepp", "Hauptstraße 13", "93547 Hintertupfing"],
"names": ["Name", "First_Name", "Address", "City"]
}
=>csv:serialize()[SENR0001] Items of type map(xs:string, array(xs:string)) cannot be serialized.
... would be nice if it could.
/Andy
[1] http://docs.basex.org/wiki/CSV_Module#XQuery
CG
Christian Grün29 May 2018 17:05 #
Hi Andy,
You can serialize the map by specifying the 'xquery' format as option:
map {
"records": ["Huber", "Sepp", "Hauptstraße 13", "93547 Hintertupfing"],
"names": ["Name", "First_Name", "Address", "City"]
}
=> csv:serialize(map { 'format': 'xquery', 'header': true() })The result:
Name,First_Name,Address,City
Huber,Sepp,Hauptstraße 13,93547 Hintertupfing
Cheers,
Christian
Quoted text · Andy Bunce · 20 lines
On Tue, May 29, 2018 at 4:43 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > The xqueryformat of CSV records as a sequence of arrays [1] is very > useful when parsing > but there seems to be no easy way to serialize from this format. Is this > correct? > > map { > "records": ["Huber", "Sepp", "Hauptstraße 13", "93547 Hintertupfing"], > "names": ["Name", "First_Name", "Address", "City"] > } > =>csv:serialize() > > [SENR0001] Items of type map(xs:string, array(xs:string)) cannot be > serialized. > > ... would be nice if it could. > /Andy > > [1] http://docs.basex.org/wiki/CSV_Module#XQuery >
AB
Andy Bunce29 May 2018 17:22 #
Ah, I thought I had tried that, but it is working now.
Thanks
/Andy
Quoted text · Christian Grün · 46 lines
On 29 May 2018 at 16:05, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Andy, > > You can serialize the map by specifying the 'xquery' format as option: > > map { > "records": ["Huber", "Sepp", "Hauptstraße 13", "93547 Hintertupfing"], > "names": ["Name", "First_Name", "Address", "City"] > } > => csv:serialize(map { 'format': 'xquery', 'header': true() }) > > The result: > > Name,First_Name,Address,City > Huber,Sepp,Hauptstraße 13,93547 Hintertupfing > > Cheers, > Christian > > > > > > On Tue, May 29, 2018 at 4:43 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > >> The xqueryformat of CSV records as a sequence of arrays [1] is very >> useful when parsing >> but there seems to be no easy way to serialize from this format. Is this >> correct? >> >> map { >> "records": ["Huber", "Sepp", "Hauptstraße 13", "93547 Hintertupfing"], >> "names": ["Name", "First_Name", "Address", "City"] >> } >> =>csv:serialize() >> >> [SENR0001] Items of type map(xs:string, array(xs:string)) cannot be >> serialized. >> >> ... would be nice if it could. >> /Andy >> >> [1] http://docs.basex.org/wiki/CSV_Module#XQuery >> > >
Written for BaseX 9.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery