cocos2d3.2解析xml

前端之家收集整理的这篇文章主要介绍了cocos2d3.2解析xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<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("%s\n",name.c_str());
原文链接:https://www.f2er.com/cocos2dx/343985.html

猜你在找的Cocos2d-x相关文章