Change node value's parsing to concatenate instead of copy it every time

This commit is contained in:
Ervin Hegedus 2025-04-28 22:34:26 +02:00
parent bf707de08f
commit e8dc60ee06
No known key found for this signature in database
GPG Key ID: 5FA5BC3F5EC41F61

View File

@ -71,6 +71,10 @@ class MSCSAXHandler {
xml_data->nodes[xml_data->nodes.size()-1]->has_child = true;
}
xml_data->currpath.append(name);
// set the current value empty
// this is necessary because if there is any text between the tags (new line, etc)
// it will be added to the current value
xml_data->currval = "";
}
void onEndElement(void * ctx, const xmlChar *localname) {
@ -92,13 +96,17 @@ class MSCSAXHandler {
}
xml_data->nodes.pop_back();
xml_data->node_depth--;
xml_data->currval = "";
}
void onCharacters(void *ctx, const xmlChar *ch, int len) {
XMLNodes* xml_data = static_cast<XMLNodes*>(ctx);
std::string content(reinterpret_cast<const char *>(ch), len);
xml_data->currval = content;
// libxml2 SAX parser will call this function multiple times
// during the parsing of a single node, if the value has multibyte
// characters, so we need to concatenate the values
xml_data->currval += content;
}
};