blob: 4b1a2737045507a86c48062adcc8c397d1785e69 (
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
59
60
61
62
63
64
65
|
#pragma once
#include <string>
#include <unordered_map>
#include <expat.h>
#include <fstream>
class SAXParser
{
public:
SAXParser();
virtual ~SAXParser();
virtual int parseFile(const std::string& filename);
virtual int parseString(const std::string& str,
const std::string& xml_source_name = "");
protected:
using attr_t = std::unordered_map<std::string, std::string>;
virtual void characterData(const std::string& data) {}
virtual void startTag(const std::string& name, const attr_t& attr) {}
virtual void endTag(const std::string& name) {}
virtual void parseError(const std::string& buf,
const std::string& error,
const std::string& xml_source_name,
std::size_t lineno);
private:
XML_Parser parser;
std::string filename;
static void characterHandler(void* parser, const XML_Char* cData, int len);
static void startHandler(void* parser, const char* el, const char** attr);
static void endHandler(void* parser, const char* el);
};
|