本文共 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/