문제

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