• c++ tinyxml


    做了一个中控项目,对xml的读取不怎么记得了,先记录在这里

    bool ReadXML(char *path)
    {
        //////////////////////////////////////////////////////////////////////////  read xml file    
        TiXmlDocument * myDocument = new TiXmlDocument(path);  //加载文件数据  
        bool IsLoad=myDocument->LoadFile();  //获取根节点  
        if(!IsLoad)
        {
        
            cout<<"Could not load:"<<path<<endl;
            return false;
        }
        else
        {
            cout<<"Load Succssed:"<<path<<endl;
        }
        
        TiXmlElement* rootElement = myDocument->RootElement();  //Root元素       count has how many DV
        
        TiXmlElement *xjf,*xjiqi,*xnode;
        xjf = rootElement->FirstChildElement();  // FirstChild元素 
        numJF =0;
        for(;xjf != NULL; xjf = xjf ->NextSiblingElement())
        {
            numJF++;
            
        }
        cout<<"numJF:"<<numJF<<endl;
        mJF = new JIFANG[numJF];
        int countjf=0,countjq =0 ,numNode = 0;
        xjf = rootElement ->FirstChildElement();
        for(;xjf!= NULL;xjf = xjf->NextSiblingElement())
        {
            TiXmlAttribute* attributeOfJF = xjf->FirstAttribute();  
            mJF[countjf].jfname =attributeOfJF->Value();
            
            countjq =0;
            xjiqi = xjf->FirstChildElement();
            for(;xjiqi !=NULL;xjiqi =xjiqi->NextSiblingElement())
            {
                countjq++;
            }
            cout<<"numjiqi:"<<countjq<<endl;
    
            
            mJF[countjf].init(countjq);
            mJF[countjf].mrect.x = paiban[countjf][0];    //set jf x,y ,w,h
            mJF[countjf].mrect.y = paiban[countjf][1];
            countjq =0;
            xjiqi = xjf->FirstChildElement();
            for(;xjiqi !=NULL;xjiqi =xjiqi->NextSiblingElement())
            {
                xnode = xjiqi->FirstChildElement();
                numNode =0 ;
                mJF[countjf].pSock[countjq].mrect.x =paiban[countjq][0];    //set jq x y w h
                mJF[countjf].pSock[countjq].mrect.y =paiban[countjq][1];
                for(;xnode!= NULL; xnode =xnode->NextSiblingElement())
                {
                    if(numNode == 0)
                    {
                        
                        mJF[countjf].pSock[countjq].name =xnode->GetText();
                        //cout<<"name:"<<mJF[countjf].pSock[countjq].name.c_str();
                    }
                    if(numNode == 1)
                    {
                        
                        mJF[countjf].pSock[countjq].m_ip= xnode->GetText();
                        //cout<<"   ip:"<<mJF[countjf].pSock[countjq].name.c_str()<<endl;
                    
                    }
                    numNode++;
                }
                countjq++;
            }
            countjf++;
        }
        
    
        for(int numofjf =0 ;numofjf<numJF ; numofjf ++)
        {
            printf("%15s   数量:%d \n",mJF[numofjf].jfname.c_str(),mJF[numofjf].nDV);
            for(int numofjq =0; numofjq<mJF[numofjf].nDV;numofjq++ )
            {
                printf("%20s ip:%s \n",mJF[numofjf].pSock[numofjq].name.c_str(),mJF[numofjf].pSock[numofjq].m_ip.c_str());
            
            }
            cout<<endl;    
        
        }
        return true;
    //////////////////////////////////////////////////////////////////////     laster do something
    
    }
  • 相关阅读:
    Beginning SDL 2.0(5) 基于MFC和SDL的YuvPlayer
    Beginning SDL 2.0(6) 音频渲染及wav播放
    Beginning SDL 2.0(4) YUV加载及渲染
    Beginning SDL 2.0(3) SDL介绍及BMP渲染
    获取windows可执行文件的version信息(版本号)
    visual studio 2005提示脚本错误 /VC/VCWizards/2052/Common.js
    Beginning SDL 2.0(2) TwinklebearDev SDL 2.0 Tutorial
    Beginning SDL 2.0(1) SDL功能简介
    ffmpeg与H264编码指南
    2015-07学习总结——网络编程(TCP/IP)
  • 原文地址:https://www.cnblogs.com/dragon2012/p/2860909.html
Copyright © 2020-2023  润新知