tinyxml第二课文件读取

 

 
  
   
    
    
   

  

 

创新互联建站专注于云安网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供云安营销型网站建设,云安网站制作、云安网页设计、云安网站官网定制、小程序定制开发服务,打造云安网络公司原创品牌,更为您提供云安网站排名全网营销落地服务。

代码

void IterChannelNode(const TiXmlNode* nodeUnit, std::vector &vecChannelInfo)
{
 const TiXmlNode* nodeChannelIter = NULL;
 nodeChannelIter = nodeUnit->IterateChildren("Channel", nodeChannelIter);

 do
 {
  if (NULL == nodeChannelIter) break;

  std::string strName = nodeChannelIter->ToElement()->Attribute("name");

  struChannelInfo channelInfo;
  channelInfo.strChannelId = nodeChannelIter->ToElement()->Attribute("id");
  channelInfo.strChannelName = nodeChannelIter->ToElement()->Attribute("name");
  vecChannelInfo.push_back(channelInfo);
  nodeChannelIter = nodeChannelIter->NextSibling();
 } while (1);
}

void IterUnitNode(const TiXmlNode* nodeDevice, std::vector &vecChannelInfo)
{
 const TiXmlNode* nodeUnitIter = NULL;
 nodeUnitIter = nodeDevice->IterateChildren("UnitNodes", nodeUnitIter);
 do
 {
  if (NULL == nodeUnitIter) break;

  IterChannelNode(nodeUnitIter, vecChannelInfo);
  nodeUnitIter = nodeUnitIter->NextSibling();
 } while (1);
}

int IterDeviceInfo(const std::string &strXML, std::vector &vecChannelInfo)
{
 if (strXML.empty()) return -1;

 TiXmlDocument doc;
 doc.LoadFile(strXML.c_str());

 TiXmlElement* root = doc.FirstChildElement();
 if (NULL == root) return -1;

 const TiXmlNode* nodeDevices = NULL;
 nodeDevices = root->IterateChildren("Devices", nodeDevices);
 if (NULL == nodeDevices) return -1;


 const TiXmlNode* nodeDevice = NULL;
 nodeDevice = nodeDevices->IterateChildren("Device", nodeDevice);

 do
 {
  if (NULL == nodeDevice) break;
  //访问第一个节点
  std::string strTypeId = nodeDevice->ToElement()->Attribute("type");
  std::cout << strTypeId << std::endl;
  IterUnitNode(nodeDevice, vecChannelInfo);
  nodeDevice = nodeDevice->NextSibling();

 } while (1);

 return 0;
}


网页名称:tinyxml第二课文件读取
标题URL:http://hxwzsj.com/article/isjdjg.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 成都网站设计 成都网站设计 高端网站建设 营销网站建设 网站设计 外贸网站建设 H5网站制作 成都网站建设 网站建设 成都网站建设 成都定制网站建设 成都网站设计 成都网站建设公司 网站建设费用 重庆网站建设 网站设计制作 高端网站设计 网站建设推广 成都网站设计 响应式网站设计 成都企业网站制作 成都企业网站设计