Serialization to jsonml / Whitespace-Handling

Thursday, 11 February 2016 · 5 messages · last reply 15 Feb 2016
GD
Günter Dunz-Wolff11 Feb 2016 13:19 #
Hi all, hi Christian I want to serialize my xml-documents to jsonml like so:
json:serialize(doc('bettelweib.xml')//*:body, map { 'format': 'jsonml' })
Inside the jsonml are lots of strings with unnecessary whitespace like: "Das Bettelweib von\n Locarno." How could I remove that whitespace and also \n during or after the serialization? Thanks for any help. Regards, Günter
CG
Christian Grün11 Feb 2016 13:20 #
Hi Günter, Did you try fn:normalize-space? Greetings from Prague, Christian
Quoted text · Günter Dunz-Wolff · 19 lines
On Thu, Feb 11, 2016 at 1:19 PM, Günter Dunz-Wolff <kleist at mail.dunzwolff.de> wrote: > Hi all, hi Christian > > I want to serialize my xml-documents to jsonml like so: > > json:serialize(doc('bettelweib.xml')//*:body, map { 'format': 'jsonml' }) > > Inside the jsonml are lots of strings with unnecessary whitespace like: > > "Das Bettelweib von\n Locarno." > > How could I remove that whitespace and also \n during or after the serialization? > > Thanks for any help. > > Regards, > > Günter
GD
Günter Dunz-Wolff13 Feb 2016 18:36 #
Hi Christian, when I'm doing json:serialize(fn:normalize-space(doc('bettelweib.xml')//*:body), map { 'format': 'jsonml' }) I get JSON serializer: Atomic values cannot be serialized Greetings from Hamburg, Günter
Quoted text · Christian Grün · 31 lines
> Am 11.02.2016 um 13:20 schrieb Christian Grün <christian.gruen at gmail.com>: > > Hi Günter, > > Did you try fn:normalize-space? > > Greetings from Prague, > Christian > > > > On Thu, Feb 11, 2016 at 1:19 PM, Günter Dunz-Wolff > <kleist at mail.dunzwolff.de> wrote: >> Hi all, hi Christian >> >> I want to serialize my xml-documents to jsonml like so: >> >> json:serialize(doc('bettelweib.xml')//*:body, map { 'format': 'jsonml' }) >> >> Inside the jsonml are lots of strings with unnecessary whitespace like: >> >> "Das Bettelweib von\n Locarno." >> >> How could I remove that whitespace and also \n during or after the serialization? >> >> Thanks for any help. >> >> Regards, >> >> Günter >
CG
Christian Grün15 Feb 2016 10:22 #
Quoted text · Günter Dunz-Wolff · 1 line
> json:serialize(fn:normalize-space(doc('bettelweib.xml')//*:body), map { 'format': 'jsonml' })
Simply calling fn:normalize-space(...) won’t be enough, as it will always return a string. To give you better help, I’d be pleased if you could provide us a little self-contained example. Maybe it’s not necessary if you have a closer look at the following example: _______________________
let $body := <body>Das Bettelweib von
                    Locarno.</body>
let $updated-body := $body update (
  for $text in .//text()
  return replace value of node $text with normalize-space($text)
)
return json:serialize($updated-body, map { 'format': 'jsonml' })
_______________________
Cheers, Christian
Quoted text · Günter Dunz-Wolff · 40 lines
> > I get > JSON serializer: Atomic values cannot be serialized > > Greetings from Hamburg, > Günter > >> Am 11.02.2016 um 13:20 schrieb Christian Grün <christian.gruen at gmail.com>: >> >> Hi Günter, >> >> Did you try fn:normalize-space? >> >> Greetings from Prague, >> Christian >> >> >> >> On Thu, Feb 11, 2016 at 1:19 PM, Günter Dunz-Wolff >> <kleist at mail.dunzwolff.de> wrote: >>> Hi all, hi Christian >>> >>> I want to serialize my xml-documents to jsonml like so: >>> >>> json:serialize(doc('bettelweib.xml')//*:body, map { 'format': 'jsonml' }) >>> >>> Inside the jsonml are lots of strings with unnecessary whitespace like: >>> >>> "Das Bettelweib von\n Locarno." >>> >>> How could I remove that whitespace and also \n during or after the serialization? >>> >>> Thanks for any help. >>> >>> Regards, >>> >>> Günter >> > >
GD
Günter Dunz-Wolff15 Feb 2016 12:02 #
In my context that code helped a lot:
for $text in .//text()
return replace value of node $text with normalize-space($text)
Thx, Günter
Quoted text · Christian Grün · 66 lines
> Am 15.02.2016 um 10:22 schrieb Christian Grün <christian.gruen at gmail.com>: > >> json:serialize(fn:normalize-space(doc('bettelweib.xml')//*:body), map { 'format': 'jsonml' }) > > Simply calling fn:normalize-space(...) won’t be enough, as it will > always return a string. > > To give you better help, I’d be pleased if you could provide us a > little self-contained example. Maybe it’s not necessary if you have a > closer look at the following example: > _______________________ > > let $body := <body>Das Bettelweib von > Locarno.</body> > let $updated-body := $body update ( > for $text in .//text() > return replace value of node $text with normalize-space($text) > ) > return json:serialize($updated-body, map { 'format': 'jsonml' }) > _______________________ > > Cheers, > Christian > > >> >> I get >> JSON serializer: Atomic values cannot be serialized >> >> Greetings from Hamburg, >> Günter >> >>> Am 11.02.2016 um 13:20 schrieb Christian Grün <christian.gruen at gmail.com>: >>> >>> Hi Günter, >>> >>> Did you try fn:normalize-space? >>> >>> Greetings from Prague, >>> Christian >>> >>> >>> >>> On Thu, Feb 11, 2016 at 1:19 PM, Günter Dunz-Wolff >>> <kleist at mail.dunzwolff.de> wrote: >>>> Hi all, hi Christian >>>> >>>> I want to serialize my xml-documents to jsonml like so: >>>> >>>> json:serialize(doc('bettelweib.xml')//*:body, map { 'format': 'jsonml' }) >>>> >>>> Inside the jsonml are lots of strings with unnecessary whitespace like: >>>> >>>> "Das Bettelweib von\n Locarno." >>>> >>>> How could I remove that whitespace and also \n during or after the serialization? >>>> >>>> Thanks for any help. >>>> >>>> Regards, >>>> >>>> Günter >>> >> >> >

⚡Generated with XQuery