简体   繁体   English

boost :: property_tree xml漂亮的打印,格式化

[英]boost::property_tree xml pretty printing, formatting

I'm following the Five Minute Tutorial and I get as output (unsurprisingly) the file debug_settings_out.xml . 我正在遵循《 五分钟教程》,并且得到了输出debug_settings_out.xml (毫不奇怪)。

But my problem is, that it isn't well formatted. 但是我的问题是,它的格式不正确。 It looks like this: 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<debug><filename>debug.log</filename><level>2</level></debug>

and I want it to look like this: 我希望它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<debug>
    <filename>debug.log</filename>
    <level>2</level>
</debug>

because it should be also manually editable. 因为它也应该可以手动编辑。 How can I achieve that? 我该如何实现?

I already found the settings I can pass to the parser, but none of them gave me the desired behaviour. 我已经找到了可以传递给解析器的设置 ,但是没有一个给我想要的行为。

The documentation of PropertyTree is pretty bad (I've recently started improving it). PropertyTree的文档非常糟糕(我最近开始对其进行改进)。 What you need to do is pass a correct xml_writer_settings object to write_xml. 您需要做的是将正确的xml_writer_settings对象传递给write_xml。

https://github.com/boostorg/property_tree/blob/master/include/boost/property_tree/detail/xml_parser_writer_settings.hpp https://github.com/boostorg/property_tree/blob/master/include/boost/property_tree/detail/xml_parser_writer_settings.hpp

write_xml(filename, tree, std::locale(),
          xml_writer_make_settings(' ', 4));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM