From 1015c96c640ea7c7de1a649a7aab0651e59dcbc1 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 20 Oct 2015 17:33:58 +0200 Subject: [PATCH] Print the file line and column number context in libxml2 error messages This used to be done by libxml2 itself when using the "generic error handler" but was lost when switching to the "structured error handler". Unfortunately, we do not have as much context as with the generic handler, which used to also print the incriminated content and point to the exact location of the error. I didn't find any easy way to get it. Signed-off-by: David Wagner --- xmlserializer/XmlSerializingContext.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xmlserializer/XmlSerializingContext.cpp b/xmlserializer/XmlSerializingContext.cpp index a3fe118a9..477cd169c 100644 --- a/xmlserializer/XmlSerializingContext.cpp +++ b/xmlserializer/XmlSerializingContext.cpp @@ -57,5 +57,10 @@ void CXmlSerializingContext::appendLineToError(const std::string& strAppend) void CXmlSerializingContext::structuredErrorHandler(void* userData, xmlErrorPtr error) { CXmlSerializingContext *self = static_cast(userData); - self->_strXmlError += error->message; + + std::string filename = (error->file != NULL) ? error->file : "(user input)"; + // xmlErrorPtr->int2 contains the column; see xmlerror.h + self->_strXmlError += filename + ":" + + std::to_string(error->line) + ":" + std::to_string(error->int2) + ": " + + error->message; }