cocos2d-x中使用tinyxml解析xml配置。如下:
tinyxml2::XMLDocument doc;
if (tinyxml2::XML_SUCCESS != doc.LoadFile(strCfgFile.c_str())) {
return ;
}
但上面的解析在android下会有问题。发无法正确解析xml文件。因此,对于android下的解析,需要使用如下方式:
1 void IXMLConfigParser::load(const std::string& strCfgFile) { 2 tinyxml2::XMLDocument doc; 3 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 4 unsigned long unSize = 0ul; 5 auto pFileContent = cocos2d::CCFileUtils::sharedFileUtils()->getFileData(strCfgFile.c_str(), "rb", &unSize); 6 if (nullptr != pFileContent && unSize > 0ul) { 7 pFileContent[unSize - 1ul] = '