现在的位置: 首页 > 综合 > 正文

cocos2d-x — CCSAXParser笔记

2013年10月01日 ⁄ 综合 ⁄ 共 493字 ⁄ 字号 评论关闭

CCSAXParser是异步解析的,而自带的libxml2库是同步解析的。

使用CCSAXParser,就要继承它,并实现startElement / endElement / textHandler三个函数,如

void HelloWorld::startElement(void *ctx, const char *name, const char **atts)
{
	if(atts){
		int i=0;
		while(atts[i])
		{
			std::string keystrN(atts[i]);
			std::string keystrV(atts[i+1]);
			i=i+2;  
		}
	}
}
void HelloWorld::endElement(void *ctx, const char *name)
{

}
void HelloWorld::textHandler(void *ctx, const char *s, int len)
{
	CC_UNUSED_PARAM(ctx);  
	std::string currString((char*)s,0,len);  
	CCLOG("s_len=%d",strlen(s));  
	CCLOG(currString.c_str());
}

抱歉!评论已关闭.