mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
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
This commit is contained in:
@@ -633,7 +633,7 @@ X034 XMLAgg YES
|
||||
X035 XMLAgg: ORDER BY option YES
|
||||
X036 XMLComment YES
|
||||
X037 XMLPI YES
|
||||
X038 XMLText NO
|
||||
X038 XMLText YES supported except for RETURNING
|
||||
X040 Basic table mapping YES
|
||||
X041 Basic table mapping: null absent YES
|
||||
X042 Basic table mapping: null as nil YES
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user