aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/xml.c
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2023-11-06 09:38:29 +0100
committerDaniel Gustafsson <dgustafsson@postgresql.org>2023-11-06 09:38:29 +0100
commit526fe0d79914b2dfcfd79effd1ab26ff62469248 (patch)
tree7d25dbd45a49eeba488ae7d1f57520babda7e336 /src/backend/utils/adt/xml.c
parent7b5275eec3a50d55f5750357b8a223cf5f0bb59f (diff)
downloadpostgresql-526fe0d79914b2dfcfd79effd1ab26ff62469248.tar.gz
postgresql-526fe0d79914b2dfcfd79effd1ab26ff62469248.zip
Add XMLText function (SQL/XML X038)
This function implements the standard XMLTest function, which converts text into xml text nodes. It uses the libxml2 function xmlEncodeSpecialChars to escape predefined entities (&"<>), so that those do not cause any conflict when concatenating the text node output with existing xml documents. This also adds a note in features.sgml about not supporting XML(SEQUENCE). The SQL specification defines a RETURNING clause to a set of XML functions, where RETURNING CONTENT or RETURNING SEQUENCE can be defined. Since PostgreSQL doesn't support XML(SEQUENCE) all of these functions operate with an implicit RETURNING CONTENT. Author: Jim Jones <jim.jones@uni-muenster.de> Reviewed-by: Vik Fearing <vik@postgresfriends.org> Discussion: https://postgr.es/m/86617a66-ec95-581f-8d54-08059cca8885@uni-muenster.de
Diffstat (limited to 'src/backend/utils/adt/xml.c')
-rw-r--r--src/backend/utils/adt/xml.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 2300c7ebf34..c401e7b8219 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -47,6 +47,7 @@
#ifdef USE_LIBXML
#include <libxml/chvalid.h>
+#include <libxml/entities.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/tree.h>
@@ -513,6 +514,27 @@ xmlcomment(PG_FUNCTION_ARGS)
}
+Datum
+xmltext(PG_FUNCTION_ARGS)
+{
+#ifdef USE_LIBXML
+ text *arg = PG_GETARG_TEXT_PP(0);
+ text *result;
+ xmlChar *xmlbuf = NULL;
+
+ xmlbuf = xmlEncodeSpecialChars(NULL, xml_text2xmlChar(arg));
+
+ Assert(xmlbuf);
+
+ result = cstring_to_text_with_len((const char *) xmlbuf, xmlStrlen(xmlbuf));
+ xmlFree(xmlbuf);
+ PG_RETURN_XML_P(result);
+#else
+ NO_XML_SUPPORT();
+ return 0;
+#endif /* not USE_LIBXML */
+}
+
/*
* TODO: xmlconcat needs to merge the notations and unparsed entities