From d28e64aff027606254b8d546218a17cbc3315fa1 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sat, 27 Feb 2016 15:20:45 +0800 Subject: [PATCH] [xml_parser] Allow element handlers to stop parsing --- base/xml_utils.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/base/xml_utils.cc b/base/xml_utils.cc index fb34153..edbd16a 100644 --- a/base/xml_utils.cc +++ b/base/xml_utils.cc @@ -19,13 +19,16 @@ xml_parser::parse(std::string const &backup_file, bool quiet) size_t total = 0; size_t input_length = get_file_length(backup_file); - while (!in.eof()) { + XML_Error error_code = XML_ERROR_NONE; + while (!in.eof() && error_code == XML_ERROR_NONE) { char buffer[4096]; in.read(buffer, sizeof(buffer)); size_t len = in.gcount(); int done = in.eof(); - if (!XML_Parse(parser_, buffer, len, done)) { + // Do not throw while normally aborted by element handlers + if (!XML_Parse(parser_, buffer, len, done) && + (error_code = XML_GetErrorCode(parser_)) != XML_ERROR_ABORTED) { ostringstream out; out << "Parse error at line " << XML_GetCurrentLineNumber(parser_)