In cocos2d-x 3.0, XML parsing does not need to find its own library, and it has been integrated for us.
Text. xml
<! --? XML version = "1.0" encoding = "utf8" standalone = "yes "? --> <! --? XML-stylesheet type = "text/XSL" href = "yxfqust. XSL "? --> <! -- Below is a student list --> <student_list> <student> <stu_num> 2012050808 </stu_num> <stu_name> crystal </stu_name> <stu_class> t74 </stu_class> <stu_class>> t74 </stu_class> </student> <stu_num> 2012050809 </stu_num> <stu_name> goodmao </stu_name> <stu_class> t77 </stu_class> </student> </student_list>
Join? Header file:. h
#include "cocos-ext.h"#include "tinyxml2/tinyxml2.h"using namespace tinyxml2;
. Cpp
// Obtain the file path const char * file_path = fileutils: getinstance ()-> fullpathforfilename ("text. XML "). c_str (); log ("external file path = % s", file_path); xmldocument * mydocment = new tinyxml2: xmldocument (); // load the file mydocment-> LoadFile (file_path); tinyxml2: xmlelement * rootelement = mydocment-> rootelement (); xmlelement * studentelement = rootelement-> firstchildelement (); while (studentelement) {xmlelement * element = studentelement-> firstchildelement (); While (element) {log ("info: % s", element-> gettext ()); element = element-> nextsiblingelement ();} studentelement = studentelement-> nextsiblingelement ();}
Print the result and practice it yourself.