diff options
Diffstat (limited to 'src/backend/utils/adt/xml.c')
-rw-r--r-- | src/backend/utils/adt/xml.c | 46 |
1 files changed, 45 insertions, 1 deletions
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 /* |