18 const std::map< std::string, std::string >& attributes = {},
19 std::string content =
"" )
20 : name_( std::move( name ) )
21 , content_( std::move( content ) )
23 attributes_.insert( attributes.begin(), attributes.end() );
28 children_.push_back( child );
37 std::vector< XML > children_;
38 std::map< std::string, std::string > attributes_;
40 [[nodiscard]] std::string
to_string(
int indent )
const
42 std::ostringstream oss;
43 std::string indent_str( indent,
' ' );
45 oss << indent_str <<
"<" << name_;
46 for (
const auto& attr : attributes_ )
48 oss <<
" " << attr.first <<
"=\"" << escape_xml( attr.second ) <<
"\"";
51 if ( children_.empty() && content_.empty() )
58 if ( !content_.empty() )
60 oss << escape_xml( content_ );
62 if ( !children_.empty() )
65 for (
const auto& child : children_ )
67 oss << child.to_string( indent + 2 );
71 oss <<
"</" << name_ <<
">\n";
77 static std::string escape_xml(
const std::string& data )
79 std::ostringstream escaped;
104 return escaped.str();