void reportError(void *ptr, xmlErrorPtr error) { ErrorInfo *errorInfo = (ErrorInfo*) ptr; assert(errorInfo); if (errorInfo->verbose) { int msglen; int domain = error->domain; const char *filename = error->file? error->file : errorInfo? errorInfo->filename : NULL; xmlTextReaderPtr reader = errorInfo->xmlReader; int line = (!filename)? 0 : (reader)? xmlTextReaderGetParserLineNumber(reader) : error->line; int column = (!filename)? 0 : (reader)? xmlTextReaderGetParserColumnNumber(reader) : error->int2; if (line) { fprintf(stderr, "%s:%d.%d: ", filename, line, column); } msglen = strlen(error->message); if (error->message[msglen-1] == '\n') error->message[msglen-1] = '\0'; fprintf(stderr, "%s", error->message); /* only print extra info if it's not in message */ if (error->str1 && strstr(error->message, error->str1) == NULL) { fprintf(stderr, ": %s", error->str1); if (error->str2 && strstr(error->message, error->str2) == NULL) { fprintf(stderr, ", %s", error->str2); } if (error->str3 && strstr(error->message, error->str3) == NULL) { fprintf(stderr, ", %s", error->str3); } } fprintf(stderr, "\n"); if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { xmlParserCtxtPtr ctxt = error->ctxt; if (ctxt) xmlParserPrintFileContext(ctxt->input); } } if (errorInfo->stop == STOP) { exit(EXIT_FAILURE); } }
void OCISchemaStructuredErrorHandler (void * /*userData*/, xmlErrorPtr error) { std::ostringstream oss; oss << "XML error: '" << error->message <<"' "; if (error->str1) oss << " extra info1: '" << error->str1 << "' "; if (error->str2) oss << " extra info2: '" << error->str2 << "' "; if (error->str3) oss << " extra info3: '" << error->str3 << "' "; oss << "on line " << error->line; if (error->ctxt) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt; xmlParserInputPtr input = ctxt->input; xmlParserPrintFileContext(input); } std::cerr << oss.str() << std::endl; }