|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "MyXmlMgr.h"
|
|
|
|
|
#include "GlobalDefine.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#include "FileMgr.h"
|
|
|
|
|
#include "GlobalFunction.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CMyXmlMgr::CMyXmlMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CMyXmlMgr::~CMyXmlMgr(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/*<2A><><EFBFBD>ɸ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
|
|
|
|
<?xml version="1.0" ?>
|
|
|
|
|
<Root>
|
|
|
|
|
<SubRecipe Name="SubRecipe1">
|
|
|
|
|
<RecipePar Name="RECIPE_PAR_NAME_LASER_FRE">
|
|
|
|
|
<ParType>Double</ParType>
|
|
|
|
|
<ParVal>1000</ParVal>
|
|
|
|
|
</RecipePar>
|
|
|
|
|
<RecipePar Name="RECIPE_PAR_NAME_LASER_CURR_1">
|
|
|
|
|
<ParType>Double</ParType>
|
|
|
|
|
<ParVal>0</ParVal>
|
|
|
|
|
</RecipePar>
|
|
|
|
|
</SubRecipe>
|
|
|
|
|
<SubRecipe Name="SubRecipe2">
|
|
|
|
|
<RecipePar Name="RECIPE_PAR_NAME_LASER_FRE">
|
|
|
|
|
<ParType>Double</ParType>
|
|
|
|
|
<ParVal>0</ParVal>
|
|
|
|
|
</RecipePar>
|
|
|
|
|
<RecipePar Name="RECIPE_PAR_NAME_LASER_CURR_1">
|
|
|
|
|
<ParType>Double</ParType>
|
|
|
|
|
<ParVal>0</ParVal>
|
|
|
|
|
</RecipePar>
|
|
|
|
|
</SubRecipe>
|
|
|
|
|
</Root>
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
//<2F>ݹ麯<DDB9><E9BAAF>
|
|
|
|
|
void CMyXmlMgr::SaveXmlItem(TiXmlElement *RootElement,CMyXmlItem &XmlItem)
|
|
|
|
|
{
|
|
|
|
|
int size = XmlItem.m_XmlItemVec.size();
|
|
|
|
|
if(size==0)//<2F>ӽڵ<D3BD>,<2C>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD>յ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
TiXmlText *XmlValContent = new TiXmlText(XmlItem.m_XmlItemName);
|
|
|
|
|
RootElement->LinkEndChild(XmlValContent);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TiXmlElement *ItemElement = new TiXmlElement(XmlItem.m_XmlItemName);
|
|
|
|
|
if(XmlItem.m_XmlItemAttributeName!="")//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
{
|
|
|
|
|
ItemElement->SetAttribute(XmlItem.m_XmlItemAttributeName, XmlItem.m_XmlItemAttributeVal);
|
|
|
|
|
}
|
|
|
|
|
RootElement->LinkEndChild(ItemElement);
|
|
|
|
|
for(int k=0;k<size;k++)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ݹ<EFBFBD>
|
|
|
|
|
SaveXmlItem(ItemElement,XmlItem.m_XmlItemVec[k]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void CMyXmlMgr::SaveXmlItemToFile(CString FilePath,CMyXmlItem &XmlItem)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>XML<4D><4C><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
TiXmlDocument *myDocument = new TiXmlDocument();
|
|
|
|
|
//XML<4D>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>
|
|
|
|
|
TiXmlDeclaration *pDeclaration = new TiXmlDeclaration(_T("1.0"),_T(""),_T(""));
|
|
|
|
|
myDocument->LinkEndChild(pDeclaration);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD>ӡ<EFBFBD>
|
|
|
|
|
TiXmlElement *RootElement = new TiXmlElement(XmlItem.m_XmlItemName);
|
|
|
|
|
myDocument->LinkEndChild(RootElement);
|
|
|
|
|
|
|
|
|
|
//<2F>ݹ<EFBFBD>
|
|
|
|
|
int size = XmlItem.m_XmlItemVec.size();
|
|
|
|
|
for(int k=0;k<size;k++)
|
|
|
|
|
{
|
|
|
|
|
SaveXmlItem(RootElement,XmlItem.m_XmlItemVec[k]);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>浽<EFBFBD>ļ<EFBFBD>
|
|
|
|
|
myDocument->SaveFile(CStringToLPCSTR(FilePath));
|
|
|
|
|
|
|
|
|
|
delete myDocument;
|
|
|
|
|
}
|
|
|
|
|
catch (string& e)
|
|
|
|
|
{
|
|
|
|
|
CString log =e.c_str();
|
|
|
|
|
log = "ReadXmlErr-->" + log;
|
|
|
|
|
gLogMgr->WriteDebugLog(log);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F>ݹ麯<DDB9><E9BAAF>
|
|
|
|
|
void CMyXmlMgr::ReadXmlItem(TiXmlElement *RootElement,CMyXmlItem &XmlItem)
|
|
|
|
|
{
|
|
|
|
|
XmlItem.m_XmlItemName = RootElement->Value();
|
|
|
|
|
TiXmlAttribute* XmlItemAttribute = RootElement->FirstAttribute();//ֻȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
if(XmlItemAttribute!=NULL)
|
|
|
|
|
{
|
|
|
|
|
XmlItem.m_XmlItemAttributeName = XmlItemAttribute->Name();
|
|
|
|
|
XmlItem.m_XmlItemAttributeVal = XmlItemAttribute->Value();
|
|
|
|
|
}
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB><EFBFBD>ӽڵ<D3BD>
|
|
|
|
|
TiXmlElement *XmlElement = RootElement->FirstChildElement();
|
|
|
|
|
if(XmlElement==NULL)//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
{
|
|
|
|
|
CMyXmlItem XmlChildItem;
|
|
|
|
|
XmlChildItem.m_XmlItemName = RootElement->GetText();
|
|
|
|
|
XmlItem.AddXmlItem(XmlChildItem);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
|
|
|
|
for(;XmlElement != NULL;XmlElement = XmlElement->NextSiblingElement())
|
|
|
|
|
{
|
|
|
|
|
CMyXmlItem XmlChildItem;
|
|
|
|
|
XmlItem.AddXmlItem(XmlChildItem);
|
|
|
|
|
vector<CMyXmlItem>&XmlItemVec = XmlItem.m_XmlItemVec;
|
|
|
|
|
int size = XmlItemVec.size();
|
|
|
|
|
//<2F>ݹ<EFBFBD>
|
|
|
|
|
ReadXmlItem(XmlElement,XmlItemVec[size-1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>xml <20>ļ<EFBFBD><C4BC>лָ<D0BB>XmlItem
|
|
|
|
|
bool CMyXmlMgr::ReadXmlItemFromFile(CString FilePath,CMyXmlItem &XmlItem)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
XmlItem.m_XmlItemVec.clear();
|
|
|
|
|
|
|
|
|
|
//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⱨ<EFBFBD><E2B1A8>
|
|
|
|
|
CFileMgr FileMgr;
|
|
|
|
|
if(!FileMgr.IsFileExist(FilePath))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>XML<4D><4C><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
TiXmlDocument *myDocument = new TiXmlDocument(CStringToLPCSTR(FilePath));
|
|
|
|
|
myDocument->LoadFile();
|
|
|
|
|
//<2F><><EFBFBD>ø<EFBFBD>Ԫ<EFBFBD><D4AA>
|
|
|
|
|
TiXmlElement *RootElement = myDocument->RootElement();
|
|
|
|
|
//<2F>ݹ<EFBFBD>
|
|
|
|
|
ReadXmlItem(RootElement,XmlItem);
|
|
|
|
|
|
|
|
|
|
delete myDocument;
|
|
|
|
|
}
|
|
|
|
|
catch (string& e)
|
|
|
|
|
{
|
|
|
|
|
CString log =e.c_str();
|
|
|
|
|
log = "ReadXmlErr-->" + log;
|
|
|
|
|
gLogMgr->WriteDebugLog(log);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|