summaryrefslogtreecommitdiff
path: root/src/xml_test.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2025-03-09 22:26:25 +0100
committerThomas Schmucker <ts@its1.de>2025-03-09 22:26:25 +0100
commit0cf833840b19e603f480dead5ca211f947503f9b (patch)
tree9b146c5644e1bb93ed0307275a6930bffe11d0ad /src/xml_test.cpp
downloadexpat++-0cf833840b19e603f480dead5ca211f947503f9b.tar.gz
expat++-0cf833840b19e603f480dead5ca211f947503f9b.tar.bz2
expat++-0cf833840b19e603f480dead5ca211f947503f9b.zip
Initial commit
Diffstat (limited to 'src/xml_test.cpp')
-rw-r--r--src/xml_test.cpp58
1 files changed, 58 insertions, 0 deletions
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 @@
1#include <iostream>
2#include <string>
3using namespace std;
4
5#include "xml.hpp"
6
7class MyXML : public XML {
8 public:
9 explicit MyXML(ostream& out, size_t indent = 4)
10 : pout_(&out)
11 , depth_(0)
12 , indent_(indent)
13 {
14 }
15
16 protected:
17 void handle_start(const string& name, const vector<pair<string, string>>& attr)
18 {
19 *pout_ << string(depth_++ * indent_, ' ')
20 << "<" << name;
21
22 auto it = cbegin(attr);
23 auto end = cend(attr);
24 if ( it != end ) {
25 *pout_ << " " << it->first << "=\"" << it->second << "\"";
26
27 ++it; // skip first Element
28 for ( ; it != end; ++it )
29 *pout_ << ", " << it->first << "=\"" << it->second << "\"";
30 }
31
32 *pout_ << ">" << endl;
33 }
34
35 void handle_end(const string& name)
36 {
37 *pout_ << string(--depth_ * indent_, ' ')
38 << "</" << name << ">"
39 << endl;
40 }
41
42 private:
43 ostream* pout_;
44 size_t depth_;
45 size_t indent_;
46};
47
48int
49main()
50{
51 try {
52 MyXML myxml(cout);
53 myxml.parse(cin);
54 }
55 catch ( exception& e ) {
56 cerr << "Fehler: " << e.what() << endl;
57 }
58}