Hi, attached is a patch that adds the function xml_encode_special_chars to the xml2 contrib module. It's against 8.0beta4. It's intended for commit.
I would have CC'ed the author, John Gray, but I was unable to find his email address. -- Markus Bertheau <[EMAIL PROTECTED]>
ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/: config.log ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/: config.status ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/contrib/xml2: libpgxml.a ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/contrib/xml2: libpgxml.so ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/contrib/xml2: libpgxml.so.0 ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/contrib/xml2: libpgxml.so.0.0 ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/contrib/xml2: pgxml.sql diff -cr postgresql-8.0.0beta4.orig/contrib/xml2/pgxml.sql.in postgresql-8.0.0beta4/contrib/xml2/pgxml.sql.in *** postgresql-8.0.0beta4.orig/contrib/xml2/pgxml.sql.in 2004-03-07 21:41:27.000000000 +0100 --- postgresql-8.0.0beta4/contrib/xml2/pgxml.sql.in 2004-11-05 12:20:42.608943509 +0100 *************** *** 3,8 **** --- 3,11 ---- CREATE OR REPLACE FUNCTION xml_valid(text) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE 'c' WITH (isStrict); + CREATE OR REPLACE FUNCTION xml_encode_special_chars(text) RETURNS text + AS 'MODULE_PATHNAME' LANGUAGE 'c' WITH (isStrict); + CREATE OR REPLACE FUNCTION xpath_string(text,text) RETURNS text AS 'MODULE_PATHNAME' LANGUAGE 'c' WITH (isStrict); diff -cr postgresql-8.0.0beta4.orig/contrib/xml2/xpath.c postgresql-8.0.0beta4/contrib/xml2/xpath.c *** postgresql-8.0.0beta4.orig/contrib/xml2/xpath.c 2004-10-13 03:26:42.000000000 +0200 --- postgresql-8.0.0beta4/contrib/xml2/xpath.c 2004-11-05 12:20:13.131025200 +0100 *************** *** 40,45 **** --- 40,46 ---- Datum xml_valid(PG_FUNCTION_ARGS); + Datum xml_encode_special_chars(PG_FUNCTION_ARGS); Datum xpath_nodeset(PG_FUNCTION_ARGS); Datum xpath_string(PG_FUNCTION_ARGS); Datum xpath_number(PG_FUNCTION_ARGS); *************** *** 186,191 **** --- 187,220 ---- } + /* Encodes special characters (<, >, &, " and \r) as XML entities */ + + PG_FUNCTION_INFO_V1(xml_encode_special_chars); + + Datum + xml_encode_special_chars(PG_FUNCTION_ARGS) + { + text *tin = PG_GETARG_TEXT_P(0); + text *tout; + int32 ressize; + xmlChar *ts, *tt; + + ts = pgxml_texttoxmlchar(tin); + + tt = xmlEncodeSpecialChars(NULL, ts); + + pfree(ts); + + ressize = strlen(tt); + tout = (text *) palloc(ressize + VARHDRSZ); + memcpy(VARDATA(tout), tt, ressize); + VARATT_SIZEP(tout) = ressize + VARHDRSZ; + + xmlFree(tt); + + PG_RETURN_TEXT_P(tout); + } + static xmlChar * pgxmlNodeSetToText(xmlNodeSetPtr nodeset, ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/contrib/xml2: xpath.o ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/contrib/xml2: xslt_proc.o ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/: GNUmakefile ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/backend/port: dynloader.c ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/backend/port: pg_sema.c ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/backend/port: pg_shmem.c ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/backend/port: tas.s ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/include: dynloader.h ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/include: pg_config.h ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/include: pg_config_os.h ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src/include: stamp-h ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src: Makefile.global ÐÐÐÑÐÐ Ð postgresql-8.0.0beta4/src: Makefile.port
---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html