From 2f8f76bcd5f175021e34bf5e23dcefc4286cb485 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sun, 14 Jan 2007 13:11:54 +0000 Subject: Add support for xmlval IS DOCUMENT expression. --- src/backend/utils/adt/xml.c | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/xml.c') diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index da04bee15de..87cb5b0d640 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.16 2007/01/12 21:47:26 petere Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.17 2007/01/14 13:11:54 petere Exp $ * *------------------------------------------------------------------------- */ @@ -515,6 +515,50 @@ xmlvalidate(PG_FUNCTION_ARGS) } +bool +xml_is_document(xmltype *arg) +{ +#ifdef USE_LIBXML + bool result; + xmlDocPtr doc = NULL; + MemoryContext ccxt = CurrentMemoryContext; + + PG_TRY(); + { + doc = xml_parse((text *) arg, true, true); + result = true; + } + PG_CATCH(); + { + ErrorData *errdata; + MemoryContext ecxt; + + ecxt = MemoryContextSwitchTo(ccxt); + errdata = CopyErrorData(); + if (errdata->sqlerrcode == ERRCODE_INVALID_XML_DOCUMENT) + { + FlushErrorState(); + result = false; + } + else + { + MemoryContextSwitchTo(ecxt); + PG_RE_THROW(); + } + } + PG_END_TRY(); + + if (doc) + xmlFreeDoc(doc); + + return result; +#else /* not USE_LIBXML */ + NO_XML_SUPPORT(); + return false; +#endif /* not USE_LIBXML */ +} + + #ifdef USE_LIBXML /* -- cgit v1.2.3