aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/xml.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2018-06-20 12:58:12 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2018-06-20 12:58:12 -0400
commite10bc161f9a675e21e7421b59c57d2b4c8eec13b (patch)
treeb870d7284b59addf017a2d3ef17d8e481c099a6f /src/backend/utils/adt/xml.c
parent99ba8d2f8f84fdc2721000dc5727a41e2ca8d944 (diff)
downloadpostgresql-e10bc161f9a675e21e7421b59c57d2b4c8eec13b.tar.gz
postgresql-e10bc161f9a675e21e7421b59c57d2b4c8eec13b.zip
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
Diffstat (limited to 'src/backend/utils/adt/xml.c')
-rw-r--r--src/backend/utils/adt/xml.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 233dd63e89b..7d1d2e019da 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -4505,11 +4505,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();
@@ -4526,13 +4536,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 = "";
}
}