summaryrefslogtreecommitdiff
path: root/include/xmlpullparser.h
blob: 18c26cd8af3640123920f4d7f6daccade50925db (plain) (blame)
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
#ifndef XMLPULLPARSER_H_
#define XMLPULLPARSER_H_

#include <string>
#include <utility>
#include <vector>

namespace newsbeuter
{

class xmlpullparser
{
public:
	enum event { START_DOCUMENT, END_DOCUMENT, START_TAG, END_TAG, TEXT };
	
	xmlpullparser();
	virtual ~xmlpullparser();
	void setInput(std::istream& is);
	int getAttributeCount() const;
	std::string getAttributeName(unsigned int index) const;
	std::string getAttributeValue(unsigned int index) const;
	std::string getAttributeValue(const std::string& name) const;
	event getEventType() const;
	std::string getText() const;
	bool isWhitespace() const;
	event next();
	
private:
	typedef std::pair<std::string,std::string> attribute;
	std::vector<attribute> attributes;
	std::string text;
	std::istream * inputstream;
	event current_event;
	
	int skip_whitespace();
	void add_attribute(std::string s);
	std::string read_tag();
	event determine_tag_type();
	std::string decode_attribute(const std::string& s);
	std::string decode_entities(const std::string& s);
	std::string decode_entity(std::string s);
	void remove_trailing_whitespace(std::string& s);
	
};

}

#endif /*XMLPULLPARSER_H_*/