--- a/src/XMLDocumentConstructor.h Tue Oct 27 22:39:50 2020 +0100
+++ b/src/XMLDocumentConstructor.h Wed Oct 28 00:05:29 2020 +0100
@@ -80,6 +80,7 @@
void process() {
current = parser->get_document()->create_root_node("yaml");
mode.push_back(Mode::ROOT);
+ std::string itemName;
while (true) {
yaml_event_t event;
@@ -110,7 +111,7 @@
} else if (event.type == YAML_SCALAR_EVENT) {
if (mode.back() == Mode::SEQUENCE) {
std::cerr << "YAML_SCALAR_EVENT: Mode::SEQUENCE: " << event.data.scalar.value << std::endl;
- current->add_child("item")->add_child_text(y2x(event.data.scalar.value));
+ current->add_child(itemName)->add_child_text(y2x(event.data.scalar.value));
} else if (mode.back() == Mode::MAPPING) {
std::cerr << "YAML_SCALAR_EVENT: Mode::MAPPING: " << event.data.scalar.value << std::endl;
current = current->add_child(y2xname(event.data.scalar.value));
@@ -126,17 +127,26 @@
} else if (event.type == YAML_SEQUENCE_START_EVENT) {
std::cerr << "YAML_SEQUENCE_START_EVENT" << std::endl;
+ xmlpp::Element* parent = current->get_parent();
+ if (parent) {
+ itemName = current->get_name();
+ parent->remove_child(current);
+ current = parent;
+ } else {
+ itemName = "item";
+ }
if (mode.back() == Mode::MAP_KEY) mode.pop_back();
mode.push_back(Mode::SEQUENCE);
} else if (event.type == YAML_SEQUENCE_END_EVENT) {
std::cerr << "YAML_SEQUENCE_END_EVENT" << std::endl;
- current = parentOrSelf(current);
mode.pop_back(); // TODO: assert sequence?
} else if (event.type == YAML_MAPPING_START_EVENT) {
- if (mode.back() == Mode::SEQUENCE) {
+ if (mode.back() == Mode::ROOT) {
+ std::cerr << "YAML_MAPPING_START_EVENT: Mode:ROOT" << std::endl;
+ } else if (mode.back() == Mode::SEQUENCE) {
std::cerr << "YAML_MAPPING_START_EVENT: Mode::SEQUENCE" << std::endl;
- current = current->add_child("item");
+ current = current->add_child(itemName);
} else if (mode.back() == Mode::MAP_KEY) {
std::cerr << "YAML_MAPPING_START_EVENT: Mode::MAP_KEY" << std::endl;
mode.pop_back();