When serializing the XML type for text, PostgreSQL does not include the XML declaration if it is not?

SELECT xmlserialize (DOCUMENT (
  SELECT xmlroot(
    xmlelement(name root, 
      xmlelement(name value, 'test')
    ), version '1.0')
  ) AS text);

returns:

<root> <& value GT; test </ & gt value; </ root>

I want (and expect):

<? xml version = '1.0'> <root> <value> test </value> </root>

Of course I could go:

SELECT '<?xml version="1.0"?> ' || xmlserialize (CONTENT (...

but then what is the point of including xmlroot?

+3
source share
1 answer

(I experimented with v8.3.7, v8.4.4 and v9.0.0 on Windows XP)

It includes an xml declaration if the parameter is standalone xmlrootused with a value of yesor no:

SELECT xmlserialize (DOCUMENT (
  SELECT xmlroot(
    xmlelement(name root, 
      xmlelement(name value, 'test')
    ), version '1.0', standalone yes)
  ) AS text);
+5
source

Source: https://habr.com/ru/post/1776143/


All Articles