【发布时间】:2013-03-03 00:33:40
【问题描述】:
我需要为我的输出创建 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>
【问题讨论】:
-
This 有效。我对这个库没有任何经验,所以我不知道这是否是最好的方法。
-
谢谢llonesmiz..你的做法也不错..印象深刻。
标签: c++ boost xml-parsing