cocos2dx中调用TinyXml读取xml配置文件 || cocos2d-x 中跨平台tinyxml读取xml文件方式
TiXmlDocument *doc = newTiXmlDocument;
#if (CC_TARGET_PLATFORM ==CC_PLATFORM_ANDROID)
//Android平台tinyxml读取文件方式(android平台需要从压缩文件中读取资源),xmlName为xml文件名称路径
unsigned char* pBuffer=NULL;
unsigned long bufferSize=0;
pBuffer=CCFileUtils::sharedFileUtils()->getFileData(xmlName, "r", &bufferSize);
if(pBuffer){
doc->Parse((const char*)pBuffer);
}else{
CCLog("android读取xml失败!");
CC_SAFE_DELETE(doc);
CC_SAFE_DELETE(pBuffer);
return;
}
#else
//ios平台tinyxml读取文件方式
if(doc->LoadFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(xmlName).c_str()) == false)
{
CCLog("ios读取xml失败!%s");
CC_SAFE_DELETE(doc);
return;
}
#endif