cocos2d-x解析xml时的Bug

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] = '';
 8     }
 9     if (nullptr == pFileContent || 0ul == unSize || tinyxml2::XML_SUCCESS != doc.Parse((const char*)(pFileContent))) {
10 #else
11     if (tinyxml2::XML_SUCCESS != doc.LoadFile(strCfgFile.c_str())) {
12 #endif
13         COLAssert(false, "load xml file error => IXMLConfigParser::load");
14         return ;
15     }
16     auto pRootNode = doc.RootElement();
17     if (nullptr == pRootNode) {
18         return ;
19     }
20     this->doLoadConfig(*pRootNode);
21 }
原文地址:https://www.cnblogs.com/tongy0/p/6729159.html