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] = '\0';
 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 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2021-07-30
  • 2021-10-03
  • 2021-12-19
相关资源
相似解决方案