-
Notifications
You must be signed in to change notification settings - Fork 11
/
XMLParser.h
59 lines (45 loc) · 1.22 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
/*!
* \file XmlParser.h
* \date 2015/05/30 11:21
*
* \author SuooL
* Contact: [email protected]
*
* \brief
*
* TODO: long description
*
* \note
*/
#ifndef __XMLParser_H__
#define __XMLParser_H__
#pragma once
#include <string>
#include "cocos2d.h"
class XMLParser : public cocos2d::Ref, public cocos2d::SAXDelegator
{
public:
// 解析指定的xml文件
static XMLParser* parseWithFile(const char *xmlFileName);
static XMLParser* parseWithString(const char *content);
XMLParser();
virtual ~XMLParser();
// 从本地xml文件读取
bool initWithFile(const char *xmlFileName);
// 从字符中读取,可用于读取网络中的xml数据
bool initWithString(const char *content);
// 对应xml标签开始,如:<string name="app_name">
virtual void startElement(void *ctx, const char *name, const char **atts);
// 对应xml标签结束,如:</string>
virtual void endElement(void *ctx, const char *name);
// 对应xml标签文本
virtual void textHandler(void *ctx, const char *s, int len);
// 获取对应标签的字符串
cocos2d::String* getString(const char *key);
private:
cocos2d::CCDictionary *m_pDictionary;
std::string m_key;
std::string startXMLElement;
std::string endXMLElement;
};
#endif