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
commitb7f0be9a7e7ec1eb7b9780b169366495f24bf975 (patch)
tree6bfea731d98d0182475d8b86193ee215930d1a44 /src/backend/utils/adt/xml.c
parent3adcad45588bff17b1253f60cf51c440e87df997 (diff)
downloadpostgresql-b7f0be9a7e7ec1eb7b9780b169366495f24bf975.tar.gz
postgresql-b7f0be9a7e7ec1eb7b9780b169366495f24bf975.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 7cdb87ef85b..8307f1cf47b 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -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 = "";
}
}