我需要为我的输出创建 xml。我有一个索引名称列表。我想以一种格式将其填充到 xml 文件中。
那是
<response>
<indexes>
<index>abc</index>
<index>xyz</index>
<index>pqr</index>
</indexes>
</response>
我的向量 index_list 中有该列表。
谁能帮我吗。
我已经为此尝试了一些代码。接下来
boost::property_tree::ptree tree;
stringstream output;
for (std::vector<string>::const_iterator it = index_list.begin();
it != index_list.end(); it++) {
std::cout << *it << "\n";
tree.put("response.indexes.index", *it);
}
if (format == "xml") {
write_xml(output, tree);
} else {
write_json(output, tree);
}
当我运行上面的代码时。我只得到列表中的姓氏。那是
<response>
<indexes>
<index>pqr</index>
</indexes>
</response>