no end of line in boost property tree xml writer output

旧时模样 提交于 2019-12-04 03:49:23

In the meantime I've found the answer. One should use xml_writer_settings, that is:

xml_writer_settings<char> settings(' ', 4);
write_xml("test.xml", model_tree, std::locale(), settings);

The first parameter in the constructor is the character used for indentation, whilst the second is the indentation length. As the solution is undocumented, hopefully this will help others facing similar problems.

Use settings while write_xml

settings Parameters

1.character indent
2:repeat times

boost::property_tree::xml_writer_settings<char> settings('\t', 1);
write_xml("xmlfilePath.xml", pt, std::locale(), settings);

With (at least) boost 1.58, you can try this:

pt::write_xml( "test.xml", 
                model_tree,  
                std::locale(),
                pt::xml_writer_make_settings< std::string >( ' ', 4) );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!