gboolean tpaw_xml_validate_from_resource (xmlDoc *doc, const gchar *dtd_resourcename) { GBytes *resourcecontents; gconstpointer resourcedata; gsize resourcesize; xmlParserInputBufferPtr buffer; xmlValidCtxt cvp; xmlDtd *dtd; GError *error = NULL; gboolean ret; DEBUG ("Loading dtd resource %s", dtd_resourcename); resourcecontents = g_resources_lookup_data (dtd_resourcename, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); if (error != NULL) { g_warning ("Unable to load dtd resource '%s': %s", dtd_resourcename, error->message); g_error_free (error); return FALSE; } resourcedata = g_bytes_get_data (resourcecontents, &resourcesize); buffer = xmlParserInputBufferCreateStatic (resourcedata, resourcesize, XML_CHAR_ENCODING_UTF8); memset (&cvp, 0, sizeof (cvp)); dtd = xmlIOParseDTD (NULL, buffer, XML_CHAR_ENCODING_UTF8); ret = xmlValidateDtd (&cvp, doc, dtd); xmlFreeDtd (dtd); g_bytes_unref (resourcecontents); return ret; }
static void testCharRanges(void) { char data[5]; xmlParserCtxtPtr ctxt; xmlParserInputBufferPtr buf; xmlParserInputPtr input; memset(data, 0, 5); /* * Set up a parsing context using the above data buffer as * the current input source. */ ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { fprintf(stderr, "Failed to allocate parser context\n"); return; } buf = xmlParserInputBufferCreateStatic(data, sizeof(data), XML_CHAR_ENCODING_NONE); if (buf == NULL) { fprintf(stderr, "Failed to allocate input buffer\n"); goto error; } input = xmlNewInputStream(ctxt); if (input == NULL) { xmlFreeParserInputBuffer(buf); goto error; } input->filename = NULL; input->buf = buf; input->cur = input->base = xmlBufContent(input->buf->buffer); input->end = input->base + 4; inputPush(ctxt, input); printf("testing char range: 1"); fflush(stdout); testCharRangeByte1(ctxt, data); printf(" 2"); fflush(stdout); testCharRangeByte2(ctxt, data); printf(" 3"); fflush(stdout); testCharRangeByte3(ctxt, data); printf(" 4"); fflush(stdout); testCharRangeByte4(ctxt, data); printf(" done\n"); fflush(stdout); error: xmlFreeParserCtxt(ctxt); }