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