Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 1015c96

Browse files
committed
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 <[email protected]>
1 parent d1c6bf3 commit 1015c96

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

xmlserializer/XmlSerializingContext.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@ void CXmlSerializingContext::appendLineToError(const std::string& strAppend)
5757
void CXmlSerializingContext::structuredErrorHandler(void* userData, xmlErrorPtr error)
5858
{
5959
CXmlSerializingContext *self = static_cast<CXmlSerializingContext *>(userData);
60-
self->_strXmlError += error->message;
60+
61+
std::string filename = (error->file != NULL) ? error->file : "(user input)";
62+
// xmlErrorPtr->int2 contains the column; see xmlerror.h
63+
self->_strXmlError += filename + ":" +
64+
std::to_string(error->line) + ":" + std::to_string(error->int2) + ": " +
65+
error->message;
6166
}

0 commit comments

Comments
 (0)