blob: 0af5b514fe6c520334336f77da821e939063d881 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include <iostream>
#include <string>
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<pair<string, string>>& 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_, ' ')
<< "</" << name << ">"
<< 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;
}
}
|