diff options
Diffstat (limited to 'src/backend/utils/adt/xml.c')
-rw-r--r-- | src/backend/utils/adt/xml.c | 24 |
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 = ""; } } |