diff --git a/include/boost/property_tree/detail/xml_parser_write.hpp b/include/boost/property_tree/detail/xml_parser_write.hpp index 0af2265fa..c8ddac384 100644 --- a/include/boost/property_tree/detail/xml_parser_write.hpp +++ b/include/boost/property_tree/detail/xml_parser_write.hpp @@ -113,12 +113,32 @@ namespace boost { namespace property_tree { namespace xml_parser // Write attributes if (optional attribs = pt.get_child_optional(xmlattr())) + { + bool attrInSeparateLine = want_pretty && settings.attr_separate_line; for (It it = attribs.get().begin(); it != attribs.get().end(); ++it) - stream << Ch(' ') << it->first << Ch('=') - << Ch('"') - << encode_char_entities( - it->second.template get_value()) - << Ch('"'); + { + if (attrInSeparateLine) + { + stream << Ch('\n'); + write_xml_indent(stream,indent+1,settings); + } + else + { + stream << Ch(' '); + } + + stream << it->first << Ch('=') + << Ch('"') + << encode_char_entities( + it->second.template get_value()) + << Ch('"'); + } + if (attrInSeparateLine) + { + stream << Ch('\n'); + write_xml_indent(stream,indent,settings); + } + } if ( has_attrs_only ) { diff --git a/include/boost/property_tree/detail/xml_parser_writer_settings.hpp b/include/boost/property_tree/detail/xml_parser_writer_settings.hpp index 5fb79f3e6..01a76b56f 100644 --- a/include/boost/property_tree/detail/xml_parser_writer_settings.hpp +++ b/include/boost/property_tree/detail/xml_parser_writer_settings.hpp @@ -16,12 +16,12 @@ namespace boost { namespace property_tree { namespace xml_parser { - + // Naively convert narrow string to another character type template Str widen(const char *text) { - typedef typename Str::value_type Ch; + typedef typename Str::value_type Ch; Str result; while (*text) { @@ -35,28 +35,32 @@ namespace boost { namespace property_tree { namespace xml_parser template class xml_writer_settings { - typedef typename Str::value_type Ch; + typedef typename Str::value_type Ch; public: xml_writer_settings(Ch inchar = Ch(' '), typename Str::size_type incount = 0, - const Str &enc = widen("utf-8")) + const Str &enc = widen("utf-8"), + bool attr_separate_line = false) : indent_char(inchar) , indent_count(incount) , encoding(enc) + , attr_separate_line(attr_separate_line) { } Ch indent_char; typename Str::size_type indent_count; Str encoding; + bool attr_separate_line; }; template xml_writer_settings xml_writer_make_settings(typename Str::value_type indent_char = (typename Str::value_type)(' '), typename Str::size_type indent_count = 0, - const Str &encoding = widen("utf-8")) + const Str &encoding = widen("utf-8"), + bool attr_separate_line = false) { - return xml_writer_settings(indent_char, indent_count, encoding); + return xml_writer_settings(indent_char, indent_count, encoding, attr_separate_line); } } } }