From 0cf833840b19e603f480dead5ca211f947503f9b Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 9 Mar 2025 22:26:25 +0100 Subject: Initial commit --- src/xml_test.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/xml_test.cpp (limited to 'src/xml_test.cpp') diff --git a/src/xml_test.cpp b/src/xml_test.cpp new file mode 100644 index 0000000..0af5b51 --- /dev/null +++ b/src/xml_test.cpp @@ -0,0 +1,58 @@ +#include +#include +using namespace std; + +#include "xml.hpp" + +class MyXML : public XML { + public: + explicit MyXML(ostream& out, size_t indent = 4) + : pout_(&out) + , depth_(0) + , indent_(indent) + { + } + + protected: + void handle_start(const string& name, const vector>& attr) + { + *pout_ << string(depth_++ * indent_, ' ') + << "<" << name; + + auto it = cbegin(attr); + auto end = cend(attr); + if ( it != end ) { + *pout_ << " " << it->first << "=\"" << it->second << "\""; + + ++it; // skip first Element + for ( ; it != end; ++it ) + *pout_ << ", " << it->first << "=\"" << it->second << "\""; + } + + *pout_ << ">" << endl; + } + + void handle_end(const string& name) + { + *pout_ << string(--depth_ * indent_, ' ') + << "" + << endl; + } + + 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() << endl; + } +} -- cgit v1.3