高效解析xml的总结,闲下来写的
需要这么几个库,直接放在你的代码工程里即可:
#include "rapidxml.h"
#include "rapidxml_utils.h"
int ReBornBossConf::loadConf(const char* szFileName){rapidxml::file fdoc(szFileName); rapidxml::xml_document doc;doc.parse<0>(fdoc.data());//! 获取根节点 rapidxml::xml_node<>* root = doc.first_node();//活动开启结束配置rapidxml::xml_node<>* pXmlRoot = root->first_node();rapidxml::xml_node<>* pXmlNode = pXmlRoot->first_node();attack_start_day = atoi(pXmlNode->first_attribute("attack_start_day")->value());attack_start_hour = atoi(pXmlNode->first_attribute("attack_start_hour")->value());attack_end_day = atoi(pXmlNode->first_attribute("attack_end_day")->value());attack_end_hour = atoi(pXmlNode->first_attribute("attack_end_hour")->value()); auction_end_day = atoi(pXmlNode->first_attribute("auction_end_day")->value());auction_end_hour = atoi(pXmlNode->first_attribute("auction_end_hour")->value());freetimes = atoi(pXmlNode->first_attribute("freetimes")->value()); freecd = atoi(pXmlNode->first_attribute("freecd")->value());//boss属性配置pXmlNode = pXmlRoot->next_sibling();for (rapidxml::xml_node<>* pChildNode = pXmlNode->first_node(); pChildNode != NULL; pChildNode = pChildNode->next_sibling()){BossAttrsConf bac;uint32_t starid=0;uint32_t starnum=0;bac.groupid= atoi(pChildNode->first_attribute("groupid")->value());bac.npcid= atoi(pChildNode->first_attribute("npcid")->value());starid = atoi(pChildNode->first_attribute("aid")->value());starnum = atoi(pChildNode->first_attribute("anum")->value());bac.conditions.insert(std::make_pair(starid, starnum));this->bossAttrs.insert(std::make_pair(bac.groupid,bac));}pXmlNode = pXmlNode->next_sibling();for (rapidxml::xml_node<>* pChildNode = pXmlNode->first_node(); pChildNode != NULL; pChildNode = pChildNode->next_sibling()){AuctionGoodsConf agc;agc.itemid= atoi(pChildNode->first_attribute("itemid")->value());agc.startprice= atoi(pChildNode->first_attribute("startprice")->value());agc.addstep = atoi(pChildNode->first_attribute("addstep")->value());this->auctionGoods.insert(std::make_pair(agc.itemid,agc));}return 0;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~