cocos2d读取xml文件

xiaoxiao2021-02-28  100

xml文件如下:

<data>     <p name="ZhangSan" age="10"/>     <p name="LiSi" age="11"/> </data>

#include <tinyxml2/tinyxml2.h> //#include <json/reader.h> #include <json/document.h>

void myTestReadXml() { auto doc = new tinyxml2::XMLDocument(); doc->Parse(FileUtils::getInstance()->getStringFromFile("data.xml").c_str()); auto root = doc->RootElement(); for (auto e = root->FirstChildElement(); e; e = e->NextSiblingElement()) { std::string str; for (auto attr = e->FirstAttribute(); attr; attr = attr->Next()) { str += attr->Name(); str += ":"; str += attr->Value(); str += ","; } log("%s", str.c_str()); } }

转载请注明原文地址: https://www.6miu.com/read-46874.html

最新回复(0)