How to serialize HTML as text

Saturday, 27 June 2020 · 3 messages
MH
Martin Honnenin reply to Emmanuel Chateau, 27 Jun 2020, 20:3227 Jun 2020 18:39 #
Quoted text · Emmanuel Chateau · 23 lines
Am 27.06.2020 um 18:32 schrieb Emmanuel Chateau: > I need to output a JSON object with HTML content without a parent element. Weird idea I grant you, but required by the people I work with. > > Working from a map, in the map value, the content should not appear in a parent element. Instead of : > > ``` > map { > ‘key' : ‘value’, > ‘content’ : <span>this is some <hi>content</hi> etc</span> > } > ``` > > I would like to output something like > > ``` > map { > ‘key' : ‘value’, > ‘content’ : 'this is some <hi>content</hi> etc' > } > ``` > > Is there a way to output some HTML content without the parent element in XQuery ? >
Assuming you have the span element node, simply call the serialize function on its child nodes e.g. serialize(<span>this is some <hi>content</hi> etc</span>/node(), map { 'method' : 'html'})
EC
Emmanuel Chateau27 Jun 2020 20:32 #
Hi, I’ve got an XQuery question more than a BaseX question. I need to output a JSON object with HTML content without a parent element. Weird idea I grant you, but required by the people I work with. Working from a map, in the map value, the content should not appear in a parent element. Instead of :
map {
    ‘key' : ‘value’,
    ‘content’ : <span>this is some <hi>content</hi> etc</span>
}
I would like to output something like
map {
    ‘key' : ‘value’,
    ‘content’ : 'this is some <hi>content</hi> etc'
}
Is there a way to output some HTML content without the parent element in XQuery ? Thanks a lot for your help, Best regards, Emmanuel
EC
Emmanuel Chateauin reply to Martin Honnen, 27 Jun 2020, 18:3927 Jun 2020 20:47 #
Wonderful, and so simple indeed ! Thanks a lot. Emmanuel
Quoted text · Martin Honnen · 34 lines
> Le 27 juin 2020 à 12:39, Martin Honnen <martin.honnen at gmx.de> a écrit : > > Am 27.06.2020 um 18:32 schrieb Emmanuel Chateau: > >> I need to output a JSON object with HTML content without a parent element. Weird idea I grant you, but required by the people I work with. >> >> Working from a map, in the map value, the content should not appear in a parent element. Instead of : >> >> ``` >> map { >> ‘key' : ‘value’, >> ‘content’ : <span>this is some <hi>content</hi> etc</span> >> } >> ``` >> >> I would like to output something like >> >> ``` >> map { >> ‘key' : ‘value’, >> ‘content’ : 'this is some <hi>content</hi> etc' >> } >> ``` >> >> Is there a way to output some HTML content without the parent element in XQuery ? >> > > Assuming you have the span element node, simply call the serialize > function on its child nodes e.g. > > serialize(<span>this is some <hi>content</hi> etc</span>/node(), map { > 'method' : 'html'}) > >

⚡Generated with XQuery