Cocos2d-x Read XML file

Source: Internet
Author: User

Cocos2d-x Read XML file

Under the Resource folder, add the Data.xml file

New-"other-" empty-"open"

A new XML file is created,

Data.xml content is as follows

<data>

<p name= "Hello" age= "All"/>

<p name= "World" age= "/>"

<p name= "People" age= "/>"

</data>

To read an XML file, first introduce the header file: #include <tinyxml2/tinyxml2.h>

Add the following code to the bool Helloworld::init ()

1     //Create a document first2Auto doc =Newtinyxml2::xmldocument ();3     //Let Doc parse the string, that is, the name of the file, (using the File tool and then accessing the C-language string)4Doc->parse (Fileutils::getinstance ()->getstringfromfile ("Data.xml"). C_STR ());5     //access to the root node6Auto root = doc->rootelement ();7     //find child objects based on root root node8     //Traverse all sub-objects (, E is not equal to NULL, next)9      for(Auto E = Root->firstchildelement (); e; e = e->nextsiblingelement ()) {Ten          OneSTD::stringstr; A          -         //iterate through all the properties in the current subkey -          for(Auto attr = E->firstattribute (); attr; attr = attr->Next ()) { thestr + = Attr->name ();//Get the name -str + =": "; -str + = Attr->value ();//Get Value -str + =", "; +         } -Log"%s", Str.c_str ());//output all the information +}

Cocos2d-x Read XML file

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.