开发者

When serializing a XML type to text, PostgreSQL does not include the the XML declaration, should it not?

开发者 https://www.devze.com 2023-01-26 19:38 出处:网络
SELECT xmlserialize (DOCUMENT ( SELECT xmlroot( xmlelement(name root, xmlelement(name value, \'test\') ), version \'1.0\')
SELECT xmlserialize (DOCUMENT (
  SELECT xmlroot(
    xmlelement(name root, 
      xmlelement(name value, 'test')
    ), version '1.0')
  ) AS text);

returns:

<root><value>test</value></root>

I want (and expected):

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

Of course I could go:

SELECT '<?x开发者_如何学Cml version="1.0"?> ' || xmlserialize (CONTENT (...

but then what is the point of including xmlroot?


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

It includes the xml declaration if the standalone option of xmlroot is used with a value of yes or no:

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

精彩评论

暂无评论...
验证码 换一张
取 消