<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());