BaseX get line-breaks return between node-data

2019-07-26 01:43发布

问题:

I'm using BaseX as my XML based DB. I make a simple query like

xquery for $Book in 
/Libraray/Literaturelist/Literature/Title return fn:data($Book)

I get all titles, just as a String that has got no line breaks.

Is there a way to add line-breaks with XQuery after each node found by the query to separate the data? This is not really dependant on my XML file because I do not add line-breaks hardcoded within the tags. ;)

回答1:

it depends on how you retrieve the query results. The most elegant way is to use the iterator, as e.g. shown in:

http://basex.org/code/QueryExample

Apart from that, you could extend your XQuery by returning an additional newline:

xquery for $Book in /Libbraray/Literaturelist/Literature/Title
return (fn:data($Book), '
')

Note, however, that the additionally output space character cannot be suppressed.

Best, Christian

PS: feel free to use the basex-talk mailing list to get feedback more quickly.



回答2:

Another way to add a newline is to explicitly use the character reference for a newline:

xquery for $Book in /Libbraray/Literaturelist/Literature/Title
return (fn:data($Book), "
")


回答3:

The XQuery 3.1 Serialization specification provides the new "adaptive" serialization mode, which outputs each XQuery result on a new line. Since BaseX 8, this mode is used as new default.