11 #ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_WRITE_HPP_INCLUDED
12 #define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_WRITE_HPP_INCLUDED
20 namespace boost {
namespace property_tree {
namespace xml_parser
39 typedef typename Str::value_type
Ch;
42 stream <<
Ch(
'<') <<
Ch(
'!') <<
Ch(
'-') <<
Ch(
'-');
44 stream <<
Ch(
'-') <<
Ch(
'-') <<
Ch(
'>');
57 typedef typename Str::value_type
Ch;
67 const typename Ptree::key_type &key,
72 typedef typename Ptree::key_type::value_type
Ch;
73 typedef typename Ptree::key_type Str;
74 typedef typename Ptree::const_iterator It;
78 bool has_elements =
false;
79 bool has_attrs_only =
pt.data().empty();
80 for (It it =
pt.begin(),
end =
pt.end(); it !=
end; ++it)
82 if (it->first != xmlattr<Str>() )
84 has_attrs_only =
false;
85 if (it->first != xmltext<Str>())
94 if (
pt.data().empty() &&
pt.empty())
99 stream <<
Ch(
'<') << key <<
112 stream <<
Ch(
'<') << key;
116 for (It it = attribs.get().begin(); it != attribs.get().end(); ++it)
117 stream <<
Ch(
' ') << it->first <<
Ch(
'=')
120 it->second.template get_value<Str>())
123 if ( has_attrs_only )
126 stream <<
Ch(
'/') <<
Ch(
'>');
136 if (has_elements && want_pretty)
142 if (!
pt.data().empty())
144 pt.template get_value<Str>(),
145 indent + 1, has_elements && want_pretty, settings);
148 for (It it =
pt.begin(); it !=
pt.end(); ++it)
150 if (it->first == xmlattr<Str>())
152 else if (it->first == xmlcomment<Str>())
154 it->second.template get_value<Str>(),
155 indent + 1, want_pretty, settings);
156 else if (it->first == xmltext<Str>())
158 it->second.template get_value<Str>(),
159 indent + 1, has_elements && want_pretty, settings);
162 indent + 1, settings);
166 if (indent >= 0 && !has_attrs_only)
170 stream <<
Ch(
'<') <<
Ch(
'/') << key <<
Ch(
'>');
178 template<
class Ptree>
181 const std::string &filename,
184 typedef typename Ptree::key_type Str;
185 stream << detail::widen<Str>(
"<?xml version=\"1.0\" encoding=\"")
187 << detail::widen<Str>(
"\"?>\n");