博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【语言-C++】Xml处理(chenlu1):UTF-8 的中文Key= 中文Value的解析()
阅读量:2192 次
发布时间:2019-05-02

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

void LoadXml(){	//TCHAR tcBuf[256];	//CString str;	//::GetModuleFileNameW(GetModuleHandle(NULL),tcBuf,256);	//str= tcBuf;	//int pos= str.ReverseFind(L'\\');	//CString strFilePath  = str.Left(pos+1);	//strFilePath = strFilePath + _T("temp\\ss.xml");	//char filePath[MAX_PATH];	//GetBuffer(strFilePath,filePath);	//char filename[512] ="D:\\Work\\DYBit\\Doc\\Materil.xml";	TiXmlDocument doc("D:\\Work\\DYBit\\Doc\\Test.xml");	if (!doc.LoadFile()) 		return;	TiXmlHandle hDoc(&doc);	//TiXmlElement* pElem;	TiXmlHandle hRoot(0);	const char *tmpChar;	TiXmlElement* pElem=hDoc.FirstChildElement().Element();	if (!pElem) 		return ;	tmpChar=pElem->Value();	hRoot=TiXmlHandle(pElem);	TiXmlElement* pMat = hRoot.FirstChild("node").Element();	if(!pMat)		return ;	DWORD dwID=0;	for(;pMat;	pMat = pMat->NextSiblingElement())	{			if(strcmp(pMat->Value(),"node")== 0)		{			CString sValue,sKeyName;			double MaxValue,MinValue;			const char *pKeyName;			const char *pValue;			double dValue;			TiXmlAttribute* pKeyNode;			for(pKeyNode = pMat->FirstAttribute();pKeyNode != pMat->LastAttribute();pKeyNode = pKeyNode->Next())			{				pKeyName = pKeyNode->Name();				sKeyName = UTF8toUnicode(pKeyName);				if (sKeyName.Compare(_T("等级")) == 0)				{					char pTmp[MAX_PATH];					pValue = pKeyNode->Value();					sValue = UTF8toUnicode(pValue);					dValue =_ttoi(sValue);				}				if (sKeyName.Compare(_T("昵称")) == 0)				{					char pTmp[MAX_PATH];					pValue = pKeyNode->Value();					sValue = UTF8toUnicode(pValue);				}				else if (sKeyName.Compare(_T("生命值")) == 0)				{					char pTmp[MAX_PATH];					pValue = pKeyNode->Value();					sValue = UTF8toUnicode(pValue);					GetBuffer(sValue,pTmp);					dValue =atoi(pTmp);					//dValue =atof(pTmp);				}								else if (sKeyName.Compare(_T("魔法值")) == 0)				{					pValue = pKeyNode->Value();					sValue = UTF8toUnicode(pValue);						int iValue = _ttoi(sValue);				}				else if (sKeyName.Compare(_T("防御力")) == 0)				{					pValue = pKeyNode->Value();					sValue = UTF8toUnicode(pValue);						dValue= _ttof(sValue)				}				else if (sKeyName.Compare(_T("攻击力")) == 0)				{					pValue = pKeyNode->Value();					sValue = UTF8toUnicode(pValue);						ParseCString(sValue,MaxValue,MinValue);				}				else if (sKeyName.Compare(_T("攻击范围")) == 0)				{					pValue = pKeyNode->Value();					sValue = UTF8toUnicode(pValue);						ParseCString(sValue,MaxValue,MinValue);				}			}		}	}}void GetBuffer(const CString &strSource,char *pStrTemp){    	int pathLength=strSource.GetLength();    	for(int i=0; i

Test.xml

转载地址:http://umjub.baihongyu.com/

你可能感兴趣的文章
算法导论阅读顺序
查看>>
Windows程序设计:直线绘制
查看>>
linux之CentOS下文件解压方式
查看>>
Django字段的创建并连接MYSQL
查看>>
div标签布局的使用
查看>>
HTML中表格的使用
查看>>
(模板 重要)Tarjan算法解决LCA问题(PAT 1151 LCA in a Binary Tree)
查看>>
(PAT 1154) Vertex Coloring (图的广度优先遍历)
查看>>
(PAT 1115) Counting Nodes in a BST (二叉查找树-统计指定层元素个数)
查看>>
(PAT 1143) Lowest Common Ancestor (二叉查找树的LCA)
查看>>
(PAT 1061) Dating (字符串处理)
查看>>
(PAT 1118) Birds in Forest (并查集)
查看>>
数据结构 拓扑排序
查看>>
(PAT 1040) Longest Symmetric String (DP-最长回文子串)
查看>>
(PAT 1145) Hashing - Average Search Time (哈希表冲突处理)
查看>>
(1129) Recommendation System 排序
查看>>
PAT1090 Highest Price in Supply Chain 树DFS
查看>>
(PAT 1096) Consecutive Factors (质因子分解)
查看>>
(PAT 1019) General Palindromic Number (进制转换)
查看>>
(PAT 1073) Scientific Notation (字符串模拟题)
查看>>