博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CMarkup 解析XML
阅读量:6771 次
发布时间:2019-06-26

本文共 4393 字,大约阅读时间需要 14 分钟。

1 #include "StdAfx.h"  2 #include "CIMFile.h"  3 #include "Markup.h"  4   5 #ifdef  UNICODE   6     #define _tcout(x) std::wcout << x;  7 #else  8     #define _tcout(x) std::cout << x;  9 #endif 10  11 char* Wide2Byte(const TCHAR* pWide) 12 { 13     char *pBytes = NULL; 14     int nLen = WideCharToMultiByte(CP_ACP,0,pWide,-1,NULL,0,NULL,NULL); 15     // get need convert length 16     int i = (int)wcslen(pWide)*sizeof(TCHAR); 17     // get need new memory size 18     pBytes = new char[i+1]; 19     if (!pBytes) // if fail then new again 20     { 21             pBytes = new char[i+1]; 22     } 23     WideCharToMultiByte(CP_ACP,0,pWide,-1,pBytes,nLen,NULL,NULL); 24     pBytes[nLen]='\0'; 25  26     return pBytes; 27 } 28  29 TCHAR* Byte2Wide(const char* pBytes) 30 { 31     TCHAR *pWide = NULL; 32  33     int nLen = MultiByteToWideChar(CP_ACP,0,pBytes,strlen(pBytes),NULL,0); 34     pWide = new wchar_t[nLen+1];     35     if (!pWide) // if fail then new again 36     { 37         pWide = new TCHAR[nLen+1]; 38     } 39     MultiByteToWideChar(CP_ACP,0,pBytes,strlen(pBytes),pWide,nLen);  40     pWide[nLen]='\0'; 41  42     return pWide; 43 } 44  45 void _FindDirFiles(tstring dirPath, tstring suffix, vector
&files) 46 { 47 TCHAR *_dirPath = new TCHAR[MAX_PATH]; 48 int len = dirPath.length() + 4; 49 _tcscpy_s(_dirPath, len, dirPath.c_str()); 50 _tcscat_s(_dirPath, len, _T("*.*")); 51 52 _finddata_t file; 53 54 char *pdirPath = Wide2Byte(_dirPath); 55 56 long lf; 57 if((lf = _findfirst(pdirPath, &file))==-1l) 58 cout<<"文件没有找到!\n"; 59 else 60 { 61 files.clear(); 62 while( _findnext( lf, &file ) == 0 ) 63 { 64 TCHAR *pName = Byte2Wide(file.name); 65 tstring str(pName); 66 int te = str.find(suffix); 67 if(te != -1){ 68 //cout<
<
&files) 91 { 92 char *pchar = new char[MAX_PATH]; 93 int len = dirPath.length() + 4; 94 strcpy_s(pchar, len, dirPath.c_str()); 95 strcat_s(pchar, len, "*.*"); 96 97 _finddata_t file; 98 99 long lf;100 if((lf = _findfirst(pchar, &file))==-1l)101 cout<<"文件没有找到!\n";102 else103 {104 files.clear();105 while( _findnext( lf, &file ) == 0 )106 {107 108 string str(file.name);109 int te = str.find(suffix.c_str());110 if(te != -1){111 //cout<
<
files;173 _FindDirFiles(strDir, suffix, files);174 int num = files.size();175 cout << " 文件总数:" << num << endl << endl;176 177 for (int i = 0; i < (int)files.size(); i++)178 {179 tstring filePath = strDir + files[i];180 int nLen = files[i].length();181 TCHAR *strTemp = new TCHAR[nLen + 1];182 _tcscpy_s(strTemp, nLen + 1, files[i].c_str());183 wcstok(strTemp, _T("_"));184 CIM_NODE::nParseTblId = _ttoi(wcstok(NULL, _T("_")));185 DELETE_POINTER(strTemp);186 187 wcout << " ["<< i << "/" << num << "] 正在解析:" << files[i].c_str();188 ParseFile(filePath.c_str());189 }190 191 wcout << " 解析完毕!" << endl;192 193 return TRUE;194 }195 196 BOOL CCIMFile::ParseFile(LPCTSTR strFilePath)197 {198 //string path = "D:\\iStudio\\svn\\SZ_REVA\\PowerES\\prog\\data\\GISCIM\\";199 200 int numsOfPSR = 0;201 202 if(!m_pXML->Load((MCD_CSTR)strFilePath))203 return FALSE;204 205 switch (CIM_NODE::nParseTblId)206 {207 case 76: // CIM_DIST_LOADSWITCHDET208 {209 m_pXML->ResetMainPos();210 CIM_NODE::strParseTblName = CIM_DIST_LOADSWITCHDET::strTblName;211 while (m_pXML->FindChildElem(MCD_CSTR(_T("cim:") + CIM_DIST_LOADSWITCHDET::strTblName)))212 {213 CIM_DIST_LOADSWITCHDET *pNode = m_arPDLoadSWDet.AddItem();214 pNode->Parse(m_pXML);215 216 mpNode.insert(pair
(pNode->nID, pNode));217 mpTbl.insert(pair
(CIM_NODE::nParseTblId, pNode));218 219 numsOfPSR++;220 }221 222 }223 break;224 }225 226 wcout << "\t 新增解析对象个数:" << numsOfPSR << " ,共 " << mpNode.size() << "个" << endl << endl;227 228 return TRUE;229 }

 

转载于:https://www.cnblogs.com/benevo/archive/2013/05/29/3106094.html

你可能感兴趣的文章
python http server handle json
查看>>
div和span显示在同一行
查看>>
谁说程序员必须要加班
查看>>
(旧)子数涵数·Flash——初识ActionScript
查看>>
SQL ★ 基本语句2
查看>>
好歌推荐---适合跑步或者骑行
查看>>
ubuntu下截图工具推荐 -- [deepin-scrot]
查看>>
8、判断三角形ABC中是否有点D
查看>>
2 Django REST Framework 开发 ---- APIView
查看>>
三:Linux 的基本命令、
查看>>
go中间的&和*
查看>>
VC6打开一个文件或工程的时候,会导致VC6崩溃而关闭
查看>>
理解和使用Linux的硬件抽象层HAL
查看>>
[Ruby on Rails系列]1、开发环境准备:Vmware和Linux的安装
查看>>
类别列表_显示树状结构
查看>>
(待写)五大常用算法:分治、动态规划、贪心、回溯和分支界定
查看>>
C++ - memset的效率和源码分析
查看>>
小程序开发过程中遇到的问题
查看>>
mysql中删除binlog的方法?mysql中如何删除binlog?
查看>>
1006. Sign In and Sign Out (25)
查看>>