| 93 | PG_FUNCTION_INFO_V1(xml_is_well_formed); |
| 94 | |
| 95 | Datum |
| 96 | xml_is_well_formed(PG_FUNCTION_ARGS) |
| 97 | { |
| 98 | text *t = PG_GETARG_TEXT_PP(0); /* document buffer */ |
| 99 | bool result = false; |
| 100 | int32 docsize = VARSIZE_ANY_EXHDR(t); |
| 101 | xmlDocPtr doctree; |
| 102 | PgXmlErrorContext *xmlerrcxt; |
| 103 | |
| 104 | xmlerrcxt = pgxml_parser_init(PG_XML_STRICTNESS_LEGACY); |
| 105 | |
| 106 | PG_TRY(); |
| 107 | { |
| 108 | doctree = xmlParseMemory((char *) VARDATA_ANY(t), docsize); |
| 109 | |
| 110 | result = (doctree != NULL); |
| 111 | |
| 112 | if (doctree != NULL) |
| 113 | xmlFreeDoc(doctree); |
| 114 | } |
| 115 | PG_CATCH(); |
| 116 | { |
| 117 | pg_xml_done(xmlerrcxt, true); |
| 118 | |
| 119 | PG_RE_THROW(); |
| 120 | } |
| 121 | PG_END_TRY(); |
| 122 | |
| 123 | pg_xml_done(xmlerrcxt, false); |
| 124 | |
| 125 | PG_RETURN_BOOL(result); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | /* Encodes special characters (<, >, &, " and \r) as XML entities */ |
nothing calls this directly
no test coverage detected