打印boost属性树生成的xml
Printing the xml generated by the boost property tree
我测试了boost::property_tree
,它很好:我可以加载XML,提取元素,保存XML等。但是,是否有可能生成XML并打印出来呢?我不想保存它。
void debug_settings::load(const std::string &filename) {
using boost::property_tree::ptree;
ptree pt;
read_xml(filename, pt);
m_file = pt.get<std::string>("debug.filename");
m_level = pt.get("debug.level", 0);
BOOST_FOREACH(ptree::value_type &v, pt.get_child("debug.modules"))m_modules.insert(v.second.data());
}
void debug_settings::save(const std::string &filename) {
using boost::property_tree::ptree;
ptree pt;
pt.put("debug.filename", m_file);
pt.put("debug.level", m_level);
BOOST_FOREACH(const std::string &name, m_modules)pt.add("debug.modules.module", name);
write_xml(filename, pt);
}
这是我用来加载和保存XML的函数。我们有显示它的方法吗?
使用以下版本的函数
template<typename Ptree>
void write_xml
(
std::basic_ostream< typename Ptree::key_type::value_type > & stream,
const Ptree & pt,
const xml_writer_settings< typename Ptree::key_type::value_type > & settings =
xml_writer_settings< typename Ptree::key_type::value_type >()
);
http://www.boost.org/doc/libs/1_52_0/doc/html/boost/property_tree/xml_parser/write_xml_id1233444.html write_xml(std::cout, pt);
用于在控制台
中输出std::ostringstream oss;
write_xml(oss, pt);
用于stringstream
的输出(可通过stringstream
的str
功能在控制台输出stringstream
内容)。
http://liveworkspace.org/code/4qV9om 4美元
您可以使用任何类型的输出流,因此std::cout可以很好地将XML打印到当前控制台
相关文章:
- boost xml parsingl将xml的路径作为变量发送
- boost::property_tree XML issue
- 如何使用 Boost XML 解析器
- Boost Read_graphml 无法正确读取 xml,它给出了所有顶点,但它们是空的
- Boost::p roperty_tree:在XML解析器中使用std::vector<>在一个键中存储多个值
- BOOST :: Archive :: XML_IARCHIVE带有XML(Deserizalisation Conte
- 如何将Boost属性树的子树序列化为XML
- 更改命名空间以自定义 Boost XML 的标记名称后的反序列化问题
- 使用 Boost c++ 解析嵌套标记的 xml
- Eclipse中的Boost TestRunner无法生成有效的XML
- boost::property_tree:复杂xml结构的解析
- 使用boost::property_tree编写CDATA XML节点
- 与boost::property_tree XML解析器一起使用时,boost::协同程序库崩溃
- 使用 Boost 属性树解析 SVG (XML)
- 如何使用 boost 的 ptree 删除 XML 的属性?
- 获取标签的子标签详细信息[BOOST PORPERTY_TREE XML]
- boost::p roperty_tree XML 漂亮的打印,格式化
- boost::spirit::xml::encode for wide string
- boost ptree的XML版本和编码
- boost属性树xml编写器输出没有结束