Is there a way to write xml using boost::property_tree, without indent characters but with new line?
Consider this code
using namespace boost::property_tree;
int main() {
ptree tree;
ptree* root = &tree.add("root", "");
root->add("something", "yes");
root->add("something2", "no");
write_xml("test.xml", tree, std::locale(), xml_writer_settings<ptree::key_type>('\n', 0));
}
When indent_count is set to 0, we get this format
<?xml version="1.0" encoding="utf-8"?>
<root><something>yes</something><something2>no</something2></root>
What I'm trying to achieve is this:
<?xml version="1.0" encoding="utf-8"?>
<root>
<something>yes</something>
<something2>no</something2>
</root>
Does anyone have an idea how to do this without adding '\n' through file manipulation? I'm using boost 1_66.
It seems like you cannot do this. Take a look at: https://github.com/boostorg/property_tree/blob/d30ff9404bd6af5cc8922a177865e566f4846b19/include/boost/property_tree/detail/xml_parser_write.hpp#L76
bool want_pretty = settings.indent_count > 0;
and then, at 101 line:
if (want_pretty)
stream << Ch('\n');
So, if you want to have new line delimiters, ya have to have one or more indenting chars in the settings.