cocos2dx3.0-tinyxml在Android環境下解析xml失敗的問題

來源:互聯網
上載者:User

標籤:

正常情況下,我們在用tinyxml讀取xml檔案的的時候,會像下面這樣寫。

1 std::string filePath = FileUtils::getInstance()->getWritablePath() + fileName;//擷取檔案路徑。2 XMLDocument *pDoc = new XMLDocument();//建立一個空的XMLDocument3 XMLError errorId = pDoc->LoadFile(filePath.c_str());//用XMLDocument來讀取檔案並進行解析,並接受傳回值。4 if (errorId != 0) {5     //這個傳回值為0時表示解析成功,其他值則表示出錯。6     return;7 }8 XMLElement *rootEle = pDoc->RootElement();//擷取根項目

 

但是當我們把cocos2dx的工程移動到Android上時,我們的xml會被壓縮到一個壓縮檔中,這樣,再調用上面的方法就會出錯,所以我們可以採取一種曲線救國的方式來解決這個問題。

1 XMLDocument pDoc;//建立一個空的XMLDocument。2 string content = FileUtils::getInstance()->getStringFromFile("test.xml");//先用FileUtils裡的工具將檔案內的內容讀進記憶體。3 pDoc.Parse(content.c_str());//再直接解析記憶體裡的內容,從而繞開了用tinyxml讀取檔案這一步4 XMLElement* root= pDoc.RootElement();//擷取根項目

 

cocos2dx3.0-tinyxml在Android環境下解析xml失敗的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.