1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Accept TEXT and CDATA nodes in XMLTABLE's column_expression.

Column expressions that match TEXT or CDATA nodes must return the
contents of the nodes themselves, not the content of non-existing
children (i.e. the empty string).

Author: Markus Winand
Reported-by: Markus Winand
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/0684A598-002C-42A2-AE12-F024A324EAE4@winand.at
This commit is contained in:
Alvaro Herrera
2018-06-20 12:58:12 -04:00
parent 3adcad4558
commit b7f0be9a7e
4 changed files with 28 additions and 24 deletions

View File

@ -4508,11 +4508,21 @@ XmlTableGetValue(TableFuncScanState *state, int colnum,
else if (count == 1)
{
xmlChar *str;
xmlNodePtr node;
str = xmlNodeListGetString(xtCxt->doc,
xpathobj->nodesetval->nodeTab[0]->xmlChildrenNode,
1);
/*
* Most nodes (elements and even attributes) store their data
* in children nodes. If they don't have children nodes, it
* means that they are empty (e.g. <element/>). Text nodes and
* CDATA sections are an exception: they don't have children
* but have content in the Text/CDATA node itself.
*/
node = xpathobj->nodesetval->nodeTab[0];
if (node->type != XML_CDATA_SECTION_NODE &&
node->type != XML_TEXT_NODE)
node = node->xmlChildrenNode;
str = xmlNodeListGetString(xtCxt->doc, node, 1);
if (str != NULL)
{
PG_TRY();
@ -4529,13 +4539,7 @@ XmlTableGetValue(TableFuncScanState *state, int colnum,
}
else
{
/*
* This line ensure mapping of empty tags to PostgreSQL
* value. Usually we would to map a empty tag to empty
* string. But this mapping can create empty string when
* user doesn't expect it - when empty tag is enforced by
* libxml2 - when user uses a text() function for example.
*/
/* Ensure mapping of empty tags to PostgreSQL values. */
cstr = "";
}
}