-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmlParser.h
100 lines (83 loc) · 2.29 KB
/
XmlParser.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef XMLPARSER_H
#define XMLPARSER_H
#include <CString.h>
#include "XmlUtils.h"
/**
* XML Handler Interface used when start element encountered
*/
class XmlParserStartHandler
{
public:
virtual void start(const XmlName &element, const char **attrs) = 0;
};
/**
* XML Handler Interface used when end element encountered
*/
class XmlParserEndHandler
{
public:
virtual void end(const XmlName &element) = 0;
};
/**
* XML Handler Interface used when characters encountered
* Ex: <element> characters </element>
*/
class XmlParserCharacterHandler
{
public:
virtual void character(const CString &data) = 0;
};
/**
* XmlParser interface
* Basically a simple SAX parser
*/
class XmlParser
{
public:
XmlParser();
virtual ~XmlParser();
void setStartHandler(XmlParserStartHandler *handler);
void setEndHandler(XmlParserEndHandler *handler);
void setCharacterHandler(XmlParserCharacterHandler *handler);
virtual void parse(const CString &xmlStr) = 0;
virtual void parseFile(const CString &xmlFile) = 0;
virtual int getLineNumber() = 0;
virtual int getColumnNumber() = 0;
protected:
XmlParserStartHandler *startHandler_;
XmlParserEndHandler *endHandler_;
XmlParserCharacterHandler *characterHandler_;
};
class XmlParserException
{
public:
XmlParserException(const CString &msg) : msg_(msg) {};
inline const CString what() const {return msg_; };
private:
CString msg_;
};
// This is just a marker exception to help distinguish
class XmlParserInvalidStateException : public XmlParserException
{
public:
XmlParserInvalidStateException(const CString &msg) : XmlParserException(msg) {};
};
// This is just a marker exception to help distinguish
class XmlParserUnknownElementException : public XmlParserException
{
public:
XmlParserUnknownElementException(const CString &msg) : XmlParserException(msg) {};
};
// This is just a marker exception to help distinguish
class XmlParserMissingAttributeException : public XmlParserException
{
public:
XmlParserMissingAttributeException(const CString &msg) : XmlParserException(msg) {};
};
// This is just a marker exception to help distinguish
class XmlParserInvalidAttributeException : public XmlParserException
{
public:
XmlParserInvalidAttributeException(const CString &msg) : XmlParserException(msg) {};
};
#endif // XMLPARSER_H