-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseXML.h
73 lines (59 loc) · 1.67 KB
/
parseXML.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
#ifndef PARSEXML__H
#define PARSEXML__H
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <expat.h>
using std::map;
using std::cout; using std::endl;
using std::string;
const int PARSE_BUFSIZE = 128;
class ParseXML {
public:
ParseXML( const string& fn ) :
lastElementTag(),
lastNonTerminal(),
filename(fn),
parser(NULL),
nextToLastTag(),
lastTag(),
xmlData()
{
// parseXML();
}
virtual ~ParseXML() { XML_ParserFree(parser); }
virtual void parseXML();
void displayData() const;
const map<string, string> getXmlData() const {
if ( xmlData.size() == 0 ) {
throw std::string("xmlData map is empty. Did you call parse()?");
}
return xmlData;
}
const string& getLastTag() const { return lastTag; }
const string& getNextToLastTag() const { return nextToLastTag; }
float getXmlFloat(const string&) const;
int getXmlInt(const string&) const;
const string& getXmlStr(const string&) const;
static void wrapper4Start(void *data, const char *el, const char **attr);
static void wrapper4End(void *data, const char *el);
static void wrapper4Chars(void *data, const char *text, int textlen);
protected:
virtual void start(const char *el, const char *attr[]);
virtual void end(const char *) {}
virtual void chars(const char *text, int textlen);
void stripTrailWhiteSpace(string&) const;
string lastElementTag;
string lastNonTerminal;
private:
const string filename;
XML_Parser parser;
char buff[PARSE_BUFSIZE];
string nextToLastTag;
string lastTag;
std::map<string, string> xmlData;
ParseXML& operator=(const ParseXML&);
ParseXML(const ParseXML&);
};
#endif