tinyxml第二課文件讀取

 <?xml version="1.0" encoding="utf-8"?>
<Organization>
 <Devices>
  <Device id="1000006" type="201">
   <UnitNodes index="0" channelnum="2" >
    <Channel id="1000006$2$0$0" name="TV1"  />
    <Channel id="1000006$2$0$1" name="TV2"  />
   </UnitNodes>
  </Device>
 </Devices>
</Organization>

創(chuàng)新互聯(lián)建站專注于云安網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供云安營銷型網(wǎng)站建設(shè),云安網(wǎng)站制作、云安網(wǎng)頁設(shè)計、云安網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造云安網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供云安網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

代碼

void IterChannelNode(const TiXmlNode* nodeUnit, std::vector<struChannelInfo> &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<struChannelInfo> &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<struChannelInfo> &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;
  //訪問第一個節(jié)點
  std::string strTypeId = nodeDevice->ToElement()->Attribute("type");
  std::cout << strTypeId << std::endl;
  IterUnitNode(nodeDevice, vecChannelInfo);
  nodeDevice = nodeDevice->NextSibling();

 } while (1);

 return 0;
}

文章標(biāo)題:tinyxml第二課文件讀取
文章出自:http://muchs.cn/article26/isjdjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、定制開發(fā)、網(wǎng)站設(shè)計、網(wǎng)站設(shè)計公司企業(yè)網(wǎng)站制作、移動網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)