After your comment I'm studying the possibility to extend the existing xmlserialize function to add the indentation feature. If so, how do you think it should look like? An extra parameter? e.g.
SELECT xmlserialize(DOCUMENT '<foo><bar>42</bar></foo>'::XML AS text, true);
.. or more or like Oracle does it
SELECT XMLSERIALIZE(DOCUMENT xmltype('<foo><bar>42</bar></foo>') AS BLOB INDENT) FROM dual;
My idea was to follow the SQL standard (part 14, SQL/XML); unfortunately, there is no free version, but there are drafts at http://www.wiscorp.com/SQLStandards.html.
<XML character string serialization> ::= XMLSERIALIZE <left paren> [ <document or content> ]
Oracle's extension SIZE=n also seems interesting (including a special case SIZE=0, which means using new-line characters without spaces for each line).