XML loading

XML loading
0.0 0


Hello, I’ve copied some xml-file into Resource folder and it’s present int apk’s assets folder with sample images (for hello world app).

Now I want to load that file using tinyxml:

const char* path = “test.xml”;
DocumentPtr document = DocumentPtr(new TiXmlDocument(path));
bool loadResult = document~~>LoadFile;
TiXmlElement* document_element = document~~>RootElement();

if (document_element != nullptr)


And this prints both: `Failed to load` and `Error`. So, it can’t find the file source to load it. What could be wrong here? Sample images are loading just by image name and it’s okay.

const char* path = CCFileUtils::sharedFileUtils() -> fullPathFromRelativePath( "test.xml" );

Only tested on cocos2d-x v2.0.4


Hm, I thought, for android, it will return same string “test.xml” ?
And what to input in the newest stable version, there are two arguments required.


You can try reading the API reference for such things.

API Reference: http://www.cocos2d-x.org/reference/native-cpp/index.html
CCFileUtils::fullPathForFilename: http://www.cocos2d-x.org/reference/native-cpp/d0/ddc/classcocos2d_1_1_c_c_file_utils.html#add09145b4e8979979f3f63b002050fb6


The problem with android is that you must unpack your xml first. Maybe my code will be of use:

std::string sceneXMLName = "Scenes/" + nextScene + ".xml";
std::string sceneXMLPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(sceneXMLName.c_str());
unsigned long size = 0;
unsigned char* pData = 0;
pData = CCFileUtils::sharedFileUtils()->getFileData(sceneXMLPath.c_str(), "rb", &size);

pugi::xml_parse_result result = sceneDescription.load_buffer(pData, size);

Instead of pugixml’s load_buffer method you may want to use smthing like

TiXmlDocument doc;
doc.Parse((const char*)filedata, 0, TIXML_ENCODING_UTF8);


You are right! The problem is that files are stored inside APK and plain c++ have no idea how to access it (because it’s zip-archive). So, I found 2 ways: one is described in your reply, the another one is a little different: load data and store it inside internal storage, for example. From that place plain c would be able to access data directly.