XMLElement() and XMLForest() embed the XML declaration of xml arguments

Поиск
Список
Период
Сортировка
Искать

XMLElement() and XMLForest() embed the XML declaration of xml arguments

От:
Jim Jones <jim.jones@uni-muenster.de>
Дата:
Вложения:
Hi

When an xml value with an XML declaration is used as element content,
xmlelement() and xmlforest() copy the declaration into the element, for
example:

== master ==

postgres=# select xmlelement(name e, ''::xml);
                    xmlelement
---------------------------------------------------
 
(1 row)

A declaration is only allowed at the start of a document, so xml_in()
rejects the result,and it cannot be restored from a dump..

postgres=# select xmlelement(name e, ''::xml)::text::xml;
ERROR:  invalid XML content
DETAIL:  line 1: XML declaration allowed only at the start of the document

        ^

For reference, xmlconcat() drops the declarations of its arguments...

postgres=# select xmlconcat(''::xml, ''::xml);
 xmlconcat
-----------
 
(1 row)

IIUC, the SQL/XML (ISO/IEC 9075-14) says that XMLELEMENT (6.15) and
XMLFOREST (6.16) take an xml argument as is and pass it to "Removing
XQuery document nodes from an XQuery sequence" (10.19), which does what
its name says: "Replace each XQuery document node in a sequence by the
sequence of children of the XQuery document node." Only the children of
the document end up in the element, and the declaration is not one of them.

The attached patch adds a flag to xml_out_internal() to omit the
declaration, and uses it in map_sql_value_to_xml_value() when an xml
value is embedded as content. Attribute values are not affected.

== patched ==

postgres=# select xmlelement(name e, ''::xml);
 xmlelement
-------------
 
(1 row)

BTW Oracle[1] and Db2[2] both drop the declaration as well.

Thoughts on this approach?

Best, Jim

1 - https://dbfiddle.uk/gyzP8Wet
2 - https://dbfiddle.uk/NL09RP-8

FAQ