如何使用boost property_tree创建XML(how to create xml usi

2019-10-17 19:59发布

我需要为我的输出创建XML。 我有指标名称的列表。 我想填充它在XML文件中的一种格式。

那是

<response>
      <indexes>
          <index>abc</index>
          <index>xyz</index>
          <index>pqr</index>
      </indexes>
</response>

我在我的向量索引 - 目录列表。

谁能帮我吗。

我已经尝试了一些代码。 随后

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);
}

当运行上述代码。 IM列表中只得到姓氏。 那是

<response>
  <indexes>
      <index>pqr</index>
  </indexes>
</response>

Answer 1:

put方法将删除任何现有的值,请参阅前面的问题, 在这里这是相关的。

你将不得不使用不同的密钥,为您的逻辑,以避免数据丢失列表中的每个条目。

加速文档说

呼叫放将在插入指定的路径新的价值,从而使调用来获取指定相同的路径检索。



文章来源: how to create xml using boost property_tree