#include #include #include using namespace std; #include "xml.hpp" class MyXML : public XML { public: explicit MyXML(ostream& out, size_t indent = 4) : pout_(&out) , indent_(indent) { } protected: void handle_start(string_view name, const vector>& attr) override { *pout_ << string(depth_++ * indent_, ' ') << "<" << name; auto start = cbegin(attr); auto end = cend(attr); if ( start != end ) { *pout_ << " " << get<0>(*start) << "=\"" << get<1>(*start) << "\""; ++start; // skip first Element for ( ; start != end; ++start ) { *pout_ << ", " << get<0>(*start) << "=\"" << get<1>(*start) << "\""; } } *pout_ << ">" << '\n'; } void handle_end(string_view name) override { *pout_ << string(--depth_ * indent_, ' ') << "" << '\n'; } void handle_cdata_start() override { *pout_ << string(depth_ * indent_, ' ') << "" << '\n'; } static bool contains_only_whitespace(span data) { return ranges::all_of(data, [](unsigned char chr) { return std::isspace(chr); }); } void handle_character_data(span data) override { if ( contains_only_whitespace(data) ) { return; } *pout_ << string(depth_ * indent_, ' ') << "Data: "; pout_->write(data.data(), static_cast(data.size())); *pout_ << '\n'; } private: ostream* pout_; size_t depth_{}; size_t indent_; }; int main() { try { MyXML myxml(cout); myxml.parse(cin); } catch ( exception& e ) { cerr << "Fehler: " << e.what() << '\n'; } }