Re: xmlserialize bug - extra empty row at the end - Mailing list pgsql-hackers

From Jim Jones
Subject Re: xmlserialize bug - extra empty row at the end
Date
Msg-id c3d5b8ba-156b-ed1e-67b3-c5934f51248a@uni-muenster.de
Whole thread Raw
In response to xmlserialize bug - extra empty row at the end  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: xmlserialize bug - extra empty row at the end  (Dmitry Dolgov <9erthalion6@gmail.com>)
Re: xmlserialize bug - extra empty row at the end  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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>
'

I'll do some digging to see if there is a good way to get rid of this 
newline or if we need to chose a different dump function.

Thanks!

Best, Jim




pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: duplicate function declaration in multirangetypes_selfuncs.c
Next
From: Dmitry Dolgov
Date:
Subject: Re: xmlserialize bug - extra empty row at the end