[BUG?] XMLSERIALIZE( ... INDENT) won't work with blank nodes

Jim Jones <jim.jones@uni-muenster.de>

From: Jim Jones <jim.jones@uni-muenster.de>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Date: 2024-08-28T08:19:48Z
Lists: pgsql-hackers

Attachments

Hi,

While testing a feature reported by Pavel in this thread[1] I realized
that elements containing whitespaces between them won't be indented with
XMLSERIALIZE( ... INDENT)

SELECT xmlserialize(DOCUMENT '<foo><bar>42</bar></foo>' AS text INDENT);

  xmlserialize   
-----------------
 <foo>          +
   <bar>42</bar>+
 </foo>         +
 
(1 row)

SELECT xmlserialize(DOCUMENT '<foo> <bar>42</bar> </foo>'::xml AS text
INDENT);
        xmlserialize        
----------------------------
 <foo> <bar>42</bar> </foo>+
 
(1 row)


Other products have a different approach[2]

Perhaps simply setting xmltotext_with_options' parameter "perserve_whitespace" to false when XMLSERIALIZE(.. INDENT) would do the trick.

doc = xml_parse(data, xmloption_arg, !indent ? true : false,
			GetDatabaseEncoding(),
			&parsed_xmloptiontype, &content_nodes,
			(Node *) &escontext);


(diff attached)

SELECT xmlserialize(DOCUMENT '<foo> <bar>42</bar> </foo>'::xml AS text
INDENT);
  xmlserialize   
-----------------
 <foo>          +
   <bar>42</bar>+
 </foo>         +
 
(1 row)

If this is indeed the way to go I can update the regression tests accordingly.

Best,

-- 
Jim

1 - https://www.postgresql.org/message-id/cbd68a31-9776-4742-9c09-4344a4c5e6dc%40uni-muenster.de
2 - https://dbfiddle.uk/zdKnfsqX

Commits

  1. Fix some whitespace issues in XMLSERIALIZE(... INDENT).