mirror of
https://github.com/postgres/postgres.git
synced 2025-07-20 05:03:10 +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:
@ -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