Cocos2d-x 3.0 uses tinyxml to parse XML files

Source: Internet
Author: User
Tags xsl

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.