Мне нужна помощь в добавлении дочернего узла ptree к существующему узлу ptree, который уже содержит значение. Проблема я столкнулся в том, что я в конечном итоге с current_module
вложенной в пределах существующего current_module
boost ptree add_child создает нежелательный вложенный элемент
так, как я пытаюсь добиться этого заключается в следующем:
std::vector<moduleStatus> moduleStatii = {
{"mod1", "file1.TXT", 0x0002},
{"mod2", "file2.TXT", 0x0003}
};
ptree pt;
pt.add("status.session_id", sessionID);
pt.put("status.start_time", timeStringUTC);
pt.put("status.load_file", loadFile);
pt.put("status.upload.estimated_loadtime", 1983);
pt.put("status.upload.time_remaining", 1613); // not finished - non-zero
// for each over the modules...
for (const auto& next : moduleStatii) {
ptree moduleStatus;
moduleStatus.put("current_module", next.moduleName);
moduleStatus.put("current_module.current_file", next.currentFile);
moduleStatus.put("current_module.status_code", next.statusCode);
pt.add_child("status.upload.current_module", moduleStatus);
}
// this is overall status - operation in progress 0x0002
pt.put("status.status_code", ss.str());
write_xml(std::cout, pt, settings);
К сожалению, выход выглядит следующим образом:
<?xml version="1.0" encoding="utf-8"?>
<status>
<session_id>123</session_id>
<start_time>Sat Sep 26 20:12:46 2015</start_time>
<load_file>/tmp/filename.zip</load_file>
<upload>
<estimated_loadtime>1983</estimated_loadtime>
<time_remaining>0</time_remaining>
<current_module>
mod1
<current_file>file1.TXT</current_file>
<status_code>3</status_code>
</current_module>
<current_module>
mod2
<current_file>file2.TXT</current_file>
<status_code>3</status_code>
</current_module>
</upload>
<status_code>0x0002</status_code>
</status>
мой живой demo показывает мой выходной ток следующим образом:
<?xml version="1.0" encoding="utf-8"?>
<status>
<session_id>123</session_id>
<start_time>Sat Sep 26 20:23:38 2015</start_time>
<load_file>/tmp/filename.zip</load_file>
<upload>
<estimated_loadtime>1983</estimated_loadtime>
<time_remaining>1613</time_remaining>
<current_module>
<current_module>
mod1
<current_file>file1.TXT</current_file>
<status_code>2</status_code>
</current_module>
</current_module>
<current_module>
<current_module>
mod2
<current_file>file2.TXT</current_file>
<status_code>3</status_code>
</current_module>
</current_module>
</upload>
<status_code>0x0002</status_code>
</status>
К сожалению, он содержит дополнительный уровень вложенности, который я не могу показать . Главное отметить, что есть значение, связанное с </current_module>
- в примере mod1
и mod2
.