> On Sun, Apr 23, 2023 at 02:02:17PM +0200, Jim Jones wrote: > On 23.04.23 07:31, Pavel Stehule wrote: > > Hi > > > > maybe I found a bug in xmlserialize > > > > SELECT xmlserialize(DOCUMENT '<foo><bar><val x="y">42</val></bar></foo>' > > AS varchar INDENT); > > > > (2023-04-23 07:27:53) postgres=# SELECT xmlserialize(DOCUMENT > > '<foo><bar><val x="y">42</val></bar></foo>' AS varchar INDENT); > > ┌─────────────────────────┐ > > │ xmlserialize │ > > ╞═════════════════════════╡ > > │ <foo> ↵│ > > │ <bar> ↵│ > > │ <val x="y">42</val>↵│ > > │ </bar> ↵│ > > │ </foo> ↵│ > > │ │ > > └─────────────────────────┘ > > (1 row) > > > > Looks so there is an extra empty row. > > > > Regards > > > > Pavel > > Hi Pavel, > > Good catch! It looks like it comes directly from libxml2. > > xmlDocPtr doc = xmlReadDoc(BAD_CAST "<foo><bar><val > x=\"y\">42</val></bar></foo>", NULL, NULL, 0 ); > xmlBufferPtr buf = NULL; > xmlSaveCtxtPtr ctxt = NULL; > > buf = xmlBufferCreate(); > ctxt = xmlSaveToBuffer(buf, NULL, XML_SAVE_NO_DECL | XML_SAVE_FORMAT); > > xmlSaveDoc(ctxt, doc); > xmlSaveClose(ctxt); > > printf("'%s'",buf->content); > > ==> > > '<foo> > <bar> > <val x="y">42</val> > </bar> > </foo> > '
It looks like this happens only if xml type is DOCUMENT, and thus xmlSaveDoc is used to save the doc directly. I might be wrong, but after a quick look at the corresponding libxml functionality it seems that a new line is getting added if the element type is not XML_XINCLUDE_{START|END}, which is unfortunate if correct.