码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x3.0 XML解析

时间:2014-05-05 13:13:56      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:cocos2d-x   xml   extension   tinyxml2   xmlelement   

在2dx3.0中xml解析已经不用自己找库了,已经为我们集成好了。

text.xml

<?xml version ="1.0" encoding ="UTF8" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="yxfqust.xsl" ?>
<!--以下是一个学生名单-->
<student_list>
	<student>
	    <stu_num>2012050808</stu_num>
	    <stu_name>crystal</stu_name>
	    <stu_class>T74</stu_class>
        <stu_class>T74</stu_class>
	</student>
	<student>
	    <stu_num> 2012050809</stu_num>
	    <stu_name>goodmao</stu_name>
	    <stu_class>T77</stu_class>
	</student>
</student_list>

添加头文件:.h

#include "cocos-ext.h"
#include "tinyxml2/tinyxml2.h"
using namespace tinyxml2;

.cpp

 //获取文件路径
        const char* file_path = FileUtils::getInstance()->fullPathForFilename("text.xml").c_str();
       log("external file path = %s",file_path);

        
        XMLDocument* myDocment = new tinyxml2::XMLDocument();
        //加载文件
        myDocment->LoadFile(file_path);
        
        tinyxml2::XMLElement* rootElement = myDocment->RootElement();
      
        
        XMLElement* studentElement = rootElement->FirstChildElement();

        while (studentElement) {
          
            
            XMLElement* element = studentElement->FirstChildElement();
            while (element) {
                 log("信息 : %s",element->GetText());
                element = element->NextSiblingElement();
                
            }
            studentElement = studentElement->NextSiblingElement();
            
        }


bubuko.com,布布扣



cocos2d-x3.0 XML解析,布布扣,bubuko.com

cocos2d-x3.0 XML解析

标签:cocos2d-x   xml   extension   tinyxml2   xmlelement   

原文地址:http://blog.csdn.net/qqmcy/article/details/24908103

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!