how to load xml file to be parsed by libxml2

how to load xml file to be parsed by libxml2
0.0 0


Hi… I am new in cocos2d-x and there’s many things that I still don’t understand how to do.
I need to parse XML file which I placed in resource/data/ folder (resource/data/test.xml) , I am able to port the code of XMLReader from the official site example without any error
but the problem now is I can’t access the xml file. it turns out that the XMLReader return NULL. so I wonder how is the right way to access the file?
I tried to move the test.xml to resource/ but there’s no good result .



Please, write example of your code ?


I think I found out before why I can’t load it. It’s kind of the problem with XCode “group” and “folder references” , I don’t know that those two are different.

but now I stumbled upon a new problem.
I have successfully load the XML in iOS Simulator but the XML cannot be loaded in Android. I use this xmlParseFile to load the XML.


XmlDocPtr doc;
doc = xmlParseFile(“data/myfile.xml”)
how is the correct way to read XML file from asset folder in Android?


Is Your app close while it try to read xml?


yes. It turn out that the XmlDocPtr is returning NULL


Did you try to use full path to the file?
Like this:
const char *xmlPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(“LanguageSpanish.xml”);


umm… I am using cocos2d-x 1.0.1-0.13.0 beta
there’s no such things as CCFileUtils::sharedFileUtils()

but yes I have tried using fullPathFromRelativePath() but the program error. it went out from the app with some kind of I/O error. (haven’t do C++ debugging on android)


A thing a bit more weird happened to me, initialy these three lines worked:
xmlDocPtr doc;
const char *fullPath = CCFileUtils::fullPathFromRelativeFile(“file.xml”, “”);
doc = xmlParseFile(fullPath)

file.xml is directly inside Resources folder.
First doc contained data, then I started to implement an iteration and so on; and suddenly while debugging I realized that doc contained NULL value.

I have got back the code to the starting point, but has been useless.
I’ve no idea what to do next as don’t know what’s the before/after difference.

I’m working with cocos2d-1.0.1-x-0.12.0, and made no change on file.xml, nor any other file, but that containing the above lines of code.
Any help?