最近在使用tinyxml提取xml文件,并递归生成菜单等级的格式
#include "stdafx.h"
#include "tinyxml\tinystr.h"
#include "tinyxml\tinyxml.h"
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <afxwin.h>
#include <map>
#include "tinyxml\tinystr.h"
#include "tinyxml\tinyxml.h"
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <afxwin.h>
#include <map>
using namespace std;
map<string, string> rootMap;
typedef struct tagEleRegister
{
string strEcuId = "";
string strCheckCmd = "";
string strCheckPos = "";
}EleRegister;
{
string strEcuId = "";
string strCheckCmd = "";
string strCheckPos = "";
}EleRegister;
typedef struct tagEleCanEcu
{
string strEcuId = "";
string strEcuShortName = "";
string strBusId = "";
string strReqId = "";
string strResId = "";
string strDisplaySeq = "";
}EleCanEcu;
{
string strEcuId = "";
string strEcuShortName = "";
string strBusId = "";
string strReqId = "";
string strResId = "";
string strDisplaySeq = "";
}EleCanEcu;
typedef struct tagVariant
{
string strVarId = "";
string strVerId = "";
string strNameStrId = "";
string strDbPath = "";
string strDbVarId = "";
string strProId = "";
string strProSddId = "";
string strEcuConfig = "";
string strFlashType = "";
}Variant;
{
string strVarId = "";
string strVerId = "";
string strNameStrId = "";
string strDbPath = "";
string strDbVarId = "";
string strProId = "";
string strProSddId = "";
string strEcuConfig = "";
string strFlashType = "";
}Variant;
typedef struct tagEleBean
{
string beanName = "";
string filePath = "";
string modelYear = "";
string bodyName = "";
string modelName = "";
}EleBean;
{
string beanName = "";
string filePath = "";
string modelYear = "";
string bodyName = "";
string modelName = "";
}EleBean;
typedef struct tagTree
{
string strContent;
vector<tagTree> vctTreeSet;
tagTree()
{
strContent = "";
vctTreeSet.clear();
}
}Tree;
{
string strContent;
vector<tagTree> vctTreeSet;
tagTree()
{
strContent = "";
vctTreeSet.clear();
}
}Tree;
typedef struct infoMenu
{
string str;
vector<infoMenu> menuList;
infoMenu()
{
str = "";
menuList.clear();
}
}tagInfo;
{
string str;
vector<infoMenu> menuList;
infoMenu()
{
str = "";
menuList.clear();
}
}tagInfo;
void WriteFileTree(ofstream& outFile, vector<Tree>& vctTreeSet, string strHead)
{
int iLoop = 0;
if (0 == vctTreeSet.size())return;
//outFile.seekp(ios::end);
for (iLoop = 0; iLoop < vctTreeSet.size(); iLoop++)
{
outFile << strHead;
outFile << vctTreeSet[iLoop].strContent;
outFile << "\n";
WriteFileTree(outFile, vctTreeSet[iLoop].vctTreeSet, strHead + "\t");
}
}
{
int iLoop = 0;
if (0 == vctTreeSet.size())return;
//outFile.seekp(ios::end);
for (iLoop = 0; iLoop < vctTreeSet.size(); iLoop++)
{
outFile << strHead;
outFile << vctTreeSet[iLoop].strContent;
outFile << "\n";
WriteFileTree(outFile, vctTreeSet[iLoop].vctTreeSet, strHead + "\t");
}
}
void WriteMenu(ofstream& outFile, vector<tagInfo>& vctTagInfo, string strHead)
{
int iLoop = 0;
if (0 == vctTagInfo.size())return;
//outFile.seekp(ios::end);
for (iLoop = 0; iLoop < vctTagInfo.size(); iLoop++)
{
outFile << strHead;
if (iLoop == 0 && "" == strHead)
outFile << vctTagInfo[iLoop].str;
else if("" == strHead)
outFile << vctTagInfo[iLoop].str + "\t\t\t\t\t\t\t\\n\\";
else
outFile << vctTagInfo[iLoop].str + "\t\t\t\t\t\t\t\\n\\";
outFile << "\n";
WriteMenu(outFile, vctTagInfo[iLoop].menuList, strHead + "\t");
}
}
{
int iLoop = 0;
if (0 == vctTagInfo.size())return;
//outFile.seekp(ios::end);
for (iLoop = 0; iLoop < vctTagInfo.size(); iLoop++)
{
outFile << strHead;
if (iLoop == 0 && "" == strHead)
outFile << vctTagInfo[iLoop].str;
else if("" == strHead)
outFile << vctTagInfo[iLoop].str + "\t\t\t\t\t\t\t\\n\\";
else
outFile << vctTagInfo[iLoop].str + "\t\t\t\t\t\t\t\\n\\";
outFile << "\n";
WriteMenu(outFile, vctTagInfo[iLoop].menuList, strHead + "\t");
}
}
void AddMenuTree(vector<Tree>& vctTreeSet,vector<string> vctStr,unsigned int uOffset)
{
unsigned int ulLoop = 0;
string strTemp;
if (vctStr.size() <= uOffset)
return;
strTemp = vctStr[uOffset];
for (ulLoop = 0; ulLoop < vctTreeSet.size(); ++ulLoop)
{
if (strTemp == vctTreeSet[ulLoop].strContent)break;
}
if (ulLoop == vctTreeSet.size())
{
vctTreeSet.push_back(Tree());
vctTreeSet[ulLoop].strContent = strTemp;
}
AddMenuTree(vctTreeSet[ulLoop].vctTreeSet, vctStr, 1 + uOffset);
}
{
unsigned int ulLoop = 0;
string strTemp;
if (vctStr.size() <= uOffset)
return;
strTemp = vctStr[uOffset];
for (ulLoop = 0; ulLoop < vctTreeSet.size(); ++ulLoop)
{
if (strTemp == vctTreeSet[ulLoop].strContent)break;
}
if (ulLoop == vctTreeSet.size())
{
vctTreeSet.push_back(Tree());
vctTreeSet[ulLoop].strContent = strTemp;
}
AddMenuTree(vctTreeSet[ulLoop].vctTreeSet, vctStr, 1 + uOffset);
}
void DealYbMaster()
{
ofstream outFile("Chrysler_Root.txt");
vector<EleBean> vctEleBean;
vector<Tree> vctTreeSet;
string strSrc = "YB_Master.xml";
//从XML提取内容
TiXmlDocument tiXmlDoc(strSrc.c_str());
if (tiXmlDoc.LoadFile())
{
TiXmlElement *pRoot = tiXmlDoc.RootElement();
for (TiXmlNode* pNodeBean = pRoot->FirstChild("bean"); NULL != pNodeBean; pNodeBean = pNodeBean->NextSibling("bean"))
{
EleBean eleBean;
for (TiXmlAttribute* pAttrBean = pNodeBean->ToElement()->FirstAttribute(); NULL != pAttrBean; pAttrBean = pAttrBean = pAttrBean->Next())
{
string strTemp;
strTemp = pAttrBean->Name();
transform(strTemp.begin(), strTemp.end(), strTemp.begin(), tolower);
&
{
ofstream outFile("Chrysler_Root.txt");
vector<EleBean> vctEleBean;
vector<Tree> vctTreeSet;
string strSrc = "YB_Master.xml";
//从XML提取内容
TiXmlDocument tiXmlDoc(strSrc.c_str());
if (tiXmlDoc.LoadFile())
{
TiXmlElement *pRoot = tiXmlDoc.RootElement();
for (TiXmlNode* pNodeBean = pRoot->FirstChild("bean"); NULL != pNodeBean; pNodeBean = pNodeBean->NextSibling("bean"))
{
EleBean eleBean;
for (TiXmlAttribute* pAttrBean = pNodeBean->ToElement()->FirstAttribute(); NULL != pAttrBean; pAttrBean = pAttrBean = pAttrBean->Next())
{
string strTemp;
strTemp = pAttrBean->Name();
transform(strTemp.begin(), strTemp.end(), strTemp.begin(), tolower);
&