加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d3.2解析xml

发布时间:2020-12-14 20:36:37 所属栏目:百科 来源:网络整理
导读:pre name="code" class="html"?xml version="1.0" encoding="UTF-8"?dicstr name ="123"111/str/dic ?xml version="1.0" encoding="UTF-8"? dicstr111/strstr112/str/dic std::string filepath = FileUtils::getInstance()-fullPathForFilename(file_path);t
<pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?>
<dic>
<str name ="123">111</str>
</dic>

<?xml version="1.0" encoding="UTF-8"?> 
<dic>
<str>111</str>
<str>112</str>
</dic>


 
 
	std::string filepath = FileUtils::getInstance()->fullPathForFilename(file_path);
	tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument();
	XMLError errorId = pDoc->LoadFile(filepath.c_str());//获取错误id;
	if (errorId != 0) {
		//xml格式错误
		log("%d",errorId);
		return;
	}
	XMLElement *rootEle = pDoc->RootElement();//主参数;
	//获取第一个节点属性
	XMLElement * dic = rootEle->FirstChildElement();//获得参数;<dic><- 这里面的是ChildElement;
	log("%s",dic->GetText());
	XMLElement * str = dic->NextSiblingElement();//相同层级的标签
	log("%s",str->GetText());


	XMLElement * dic = rootEle->FirstChildElement();
	log("%s",dic->GetText());
	string name = dic->Attribute("name");
	log("%sn",name.c_str());

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读