On 18.02.23 19:09, Peter Eisentraut wrote:
> On 17.02.23 23:24, Nikolay Samokhvalov wrote:
>>
>> 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
>> <http://www.wiscorp.com/SQLStandards.html>.
>>
>> <XML character string serialization> ::= XMLSERIALIZE <left paren> [
>> <document or content> ]
>>
>> <XML value expression> AS <data type> [ <XML serialize bom> ] [ <XML
>> serialize version> ] [ <XML declaration option> ]
>>
>> [ <XML serialize indent> ] <right paren>
>>
>> <XML serialize indent> ::= [ NO ] INDENT
>
> Good find. It would be better to use this standard syntax.
As suggested by Peter and Nikolay, v15 now removes the xmlformat
function from the catalog and adds the [NO] INDENT option to
xmlserialize, as described in X069.
postgres=# SELECT xmlserialize(DOCUMENT '<foo><bar><val
x="y">42</val></bar></foo>' AS text INDENT);
xmlserialize
----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>+
<foo> +
<bar> +
<val x="y">42</val> +
</bar> +
</foo> +
(1 row)
postgres=# SELECT xmlserialize(DOCUMENT '<foo><bar><val
x="y">42</val></bar></foo>' AS text NO INDENT);
xmlserialize
-------------------------------------------
<foo><bar><val x="y">42</val></bar></foo>
(1 row)
Although the indent feature is designed to work with xml strings of type
DOCUMENT, this implementation also allows the usage of CONTENT type
strings as long as it contains a well-formed xml. It will throw an error
otherwise.
Thanks!
Best, Jim