Rico-E
Rico-E

Reputation: 1844

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.

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.

Upvotes: 3

Views: 3807

Answers (1)

Sebastian Redl
Sebastian Redl

Reputation: 72063

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));

Upvotes: 7

Related Questions