I'm following the Five Minute Tutorial and I get as output (unsurprisingly) the file 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). What you need to do is pass a correct xml_writer_settings object to write_xml.

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归因
不隶属于 StackOverflow
scroll top