📄 xmlparse.cpp
字号:
// XmlParse.cpp: implementation of the CXmlParse class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "XmlParse.h"
#include "XmlElement.h"
//#pragma comment (lib,"WLDAP32.lib")
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//static char *strdata= new char[409600];
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CXmlParse CXmlParse::m_XmlParse;
CXmlParse::CXmlParse()
{
IniParse();
}
CXmlParse::~CXmlParse()
{
UnParseXML();
}
void CXmlParse::ParseVersion(CStringArray& arr,CString SysName,CString FileName)
{//解析本地版本文件,得到各安装文件的版本信息
arr.RemoveAll();
int xmlsize=0;
int lensxml=0;
char *strdata1= new char[40960];
char *tmps=new char[2048];
strcpy(strdata1,"");
CStdioFile csf;
if(!csf.Open(FileName,CFile::modeRead | CFile::shareDenyWrite))
{
return;
}
else
{
while((lensxml=csf.Read(tmps,2048))>0)
{
for(int rr=0;rr<lensxml;rr++)
{
strdata1[xmlsize+rr]=tmps[rr];
}
xmlsize+=lensxml;
}
csf.Close();
}
char *tmp=new char[200];
strcpy(tmp,"<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
for(int i=0;i < (int)strlen(tmp);i++)
{
strdata1[i]=tmp[i];
}
strdata1[xmlsize]='\0';
VARIANT_BOOL bSuccess=false;
if( m_iXMLDoc->loadXML(CComBSTR(strdata1),&bSuccess) == S_OK)
{
CString temp;
int id=0;
if(m_iXMLDoc->get_documentElement(&m_iRootElm) == S_OK)
{
CXmlElement eroot(m_iRootElm);
CXmlElement elem = eroot.subnode(L"SysName",L"name",SysName);
if(elem.val().GetLength() > 0)//找到相应的系统
{
CXmlElement EleAction = elem.subnode(L"file",L"id",inttostr(id));
while(EleAction.val().GetLength() > 0)
{//得到指定违法类型的全部违法行为和违反规定
arr.Add(EleAction.attr("name"));
arr.Add(EleAction.val());
EleAction = elem.subnode(L"file",L"id",inttostr(++id));
}
}
}
m_iRootElm.Release();
}
}
void CXmlParse::ParseConfig(CStringArray& arr){
int xmlsize=0;
int lensxml=0;
char *strdata1= new char[40960];
char *tmps=new char[2048];
strcpy(strdata1,"");
CStdioFile csf;
if(!csf.Open(_T("\\My Documents\\selfinfo.txt"),CFile::modeRead | CFile::shareDenyWrite))
{
return;
}
else
{
while((lensxml=csf.Read(tmps,2048))>0)
{
for(int rr=0;rr<lensxml;rr++)
{
strdata1[xmlsize+rr]=tmps[rr];
}
xmlsize+=lensxml;
}
csf.Close();
}
char *tmp=new char[200];
strcpy(tmp,"<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
for(int i=0;i < (int)strlen(tmp);i++)
{
strdata1[i]=tmp[i];
}
VARIANT_BOOL bSuccess=false;
if( m_iXMLDoc->loadXML(CComBSTR(strdata1),&bSuccess) == S_OK)
{
CString temp;
if(m_iXMLDoc->get_documentElement(&m_iRootElm) == S_OK)
{
CXmlElement eroot(m_iRootElm);
arr.Add(eroot.subnode(L"loginid").val());
}
m_iRootElm.Release();
}
}
void CXmlParse::GetFileInfo(CString xmlStr,int& fileCount,CString& filePath){
//读取查询得到的文件
if(!xmlStr.IsEmpty())
{
VARIANT_BOOL bSuccess=false;
char *tmp=new char[200];
strcpy(tmp,"<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
for(int i=0;i < (int)strlen(tmp);i++)
xmlStr.SetAt(i,tmp[i]);
if( m_iXMLDoc->loadXML(CComBSTR(xmlStr),&bSuccess) == S_OK)
{
CString temp;
if(m_iXMLDoc->get_documentElement(&m_iRootElm) == S_OK)
{
CXmlElement eroot(m_iRootElm);
CXmlElement eResultMsg = eroot.subnode(L"resultMsg");
temp = eResultMsg.val();
WideCharToMultiByte(CP_ACP,0,temp.GetBuffer(temp.GetLength()),-1,tmp,200,NULL,NULL);
fileCount = atoi(tmp);
if(fileCount > 0)
{
filePath = eroot.subnode(L"data-message").val();
}
m_iRootElm.Release();
}
}
}
}
void CXmlParse::GetIllegalInfo(CString OpeType,CStringArray &IllegalType,CStringArray &IllegalAction,CStringArray &DisobeyRule,CStringArray &IllegalDetail,CStringArray &IllegalCode)
{//根据业务类型,得到违法类型,违法行为,违反规定
IllegalType.RemoveAll();
IllegalAction.RemoveAll();
DisobeyRule.RemoveAll();
IllegalDetail.RemoveAll();
IllegalCode.RemoveAll();
int xmlsize=0;
int lensxml=0;
char *strdata1= new char[40960];
char *tmps=new char[2048];
strcpy(strdata1,"");
CStdioFile csf;
if(!csf.Open(_T("\\My Documents\\law.xml"),CFile::modeRead | CFile::shareDenyWrite))
{
return;
}
else
{
while((lensxml=csf.Read(tmps,2048))>0)
{
for(int rr=0;rr<lensxml;rr++)
{
strdata1[xmlsize+rr]=tmps[rr];
}
xmlsize+=lensxml;
}
csf.Close();
}
char *tmp=new char[200];
strcpy(tmp,"<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
for(int i=0;i < (int)strlen(tmp);i++)
{
strdata1[i]=tmp[i];
}
strdata1[xmlsize]='\0';
VARIANT_BOOL bSuccess=false;
if( m_iXMLDoc->loadXML(CComBSTR(strdata1),&bSuccess) == S_OK)
{
if(m_iXMLDoc->get_documentElement(&m_iRootElm) == S_OK)
{
CXmlElement eroot(m_iRootElm);
CXmlElement elem = eroot.subnode(L"OperationType",L"name",OpeType);
if(elem.val().GetLength() > 0){//找到指定的业务类型
int cnt=1;
CXmlElement tmpEle = elem.subnode(L"IllegalType",L"id",inttostr(cnt));
while(tmpEle.val().GetLength() > 0){//得到第一个业务类型的全部违法类型
IllegalType.Add(tmpEle.attr("name"));
if(cnt==1)
{
int m=1;
CXmlElement EleAction = tmpEle.subnode(L"IllegalAction",L"id",inttostr(m));
while(EleAction.val().GetLength() > 0)
{//得到第一个违法类型的全部违法行为和违反规定
IllegalAction.Add(EleAction.attr("name"));
DisobeyRule.Add(EleAction.attr("rule"));
IllegalCode.Add(EleAction.attr("code"));
IllegalDetail.Add(EleAction.val());
EleAction = tmpEle.subnode(L"IllegalAction",L"id",inttostr(++m));
}
}
tmpEle = elem.subnode(L"IllegalType",L"id",inttostr(++cnt));
}
}
}
m_iRootElm.Release();
}
}
void CXmlParse::GetIllegalAction(CString OpeType,CString IllegalType,CStringArray &IllegalAction,CStringArray &DisobeyRule,CStringArray &IllegalDetail,CStringArray &IllegalCode)
{//根据业务类型,违法类型,得到违法行为,违反规定
IllegalAction.RemoveAll();
DisobeyRule.RemoveAll();
IllegalDetail.RemoveAll();
IllegalCode.RemoveAll();
int xmlsize=0;
int lensxml=0;
char *strdata1= new char[40960];
char *tmps=new char[2048];
strcpy(strdata1,"");
CStdioFile csf;
if(!csf.Open(_T("\\My Documents\\law.xml"),CFile::modeRead | CFile::shareDenyWrite))
{
return;
}
else
{
while((lensxml=csf.Read(tmps,2048))>0)
{
for(int rr=0;rr<lensxml;rr++)
{
strdata1[xmlsize+rr]=tmps[rr];
}
xmlsize+=lensxml;
}
csf.Close();
}
char *tmp=new char[200];
strcpy(tmp,"<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
for(int i=0;i < (int)strlen(tmp);i++)
{
strdata1[i]=tmp[i];
}
strdata1[xmlsize]='\0';
VARIANT_BOOL bSuccess=false;
if( m_iXMLDoc->loadXML(CComBSTR(strdata1),&bSuccess) == S_OK)
{
CString temp;
int id=1;
if(m_iXMLDoc->get_documentElement(&m_iRootElm) == S_OK)
{
CXmlElement eroot(m_iRootElm);
CXmlElement elem = eroot.subnode(L"OperationType",L"name",OpeType);
if(elem.val().GetLength() > 0)//找到相应的业务类型
{
elem = elem.subnode(L"IllegalType",L"name",IllegalType);
if(elem.val().GetLength() >0)//找到相应的违法类型
{
CXmlElement EleAction = elem.subnode(L"IllegalAction",L"id",inttostr(id));
while(EleAction.val().GetLength() > 0)
{//得到指定违法类型的全部违法行为和违反规定
IllegalAction.Add(EleAction.attr("name"));
DisobeyRule.Add(EleAction.attr("rule"));
IllegalCode.Add(EleAction.attr("code"));
IllegalDetail.Add(EleAction.val());
EleAction = elem.subnode(L"IllegalAction",L"id",inttostr(++id));
}
}
}
}
m_iRootElm.Release();
}
}
void CXmlParse::GetLawInfo(CStringArray& OpeType,CStringArray &IllegalType,CStringArray &IllegalAction,CStringArray &DisobeyRule,CStringArray &IllegalDetail,CStringArray &IllegalCode)
{//得到业务类型,违法类型,违法行为,违反规定,违法编号
OpeType.RemoveAll();
IllegalType.RemoveAll();
IllegalAction.RemoveAll();
DisobeyRule.RemoveAll();
IllegalCode.RemoveAll();
IllegalDetail.RemoveAll();
int xmlsize=0;
int lensxml=0;
char *strdata1= new char[40960];
char *tmps=new char[2048];
strcpy(strdata1,"");
CStdioFile csf;
if(!csf.Open(_T("\\My Documents\\law.xml"),CFile::modeRead | CFile::shareDenyWrite))
{
return;
}
else
{
while((lensxml=csf.Read(tmps,2048))>0)
{
for(int rr=0;rr<lensxml;rr++)
{
strdata1[xmlsize+rr]=tmps[rr];
}
xmlsize+=lensxml;
}
csf.Close();
}
char *tmp=new char[200];
strcpy(tmp,"<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
for(int i=0;i < (int)strlen(tmp);i++)
{
strdata1[i]=tmp[i];
}
strdata1[xmlsize]='\0';
VARIANT_BOOL bSuccess=false;
if( m_iXMLDoc->loadXML(CComBSTR(strdata1),&bSuccess) == S_OK)
{
CString temp;
int id=1;
if(m_iXMLDoc->get_documentElement(&m_iRootElm) == S_OK)
{
CXmlElement eroot(m_iRootElm);
CXmlElement elem = eroot.subnode(L"OperationType",L"id",inttostr(id));
while(elem.val().GetLength() > 0){//得到全部的业务类型
OpeType.Add(elem.attr(L"name"));
if(id==1){
int cnt=1;
CXmlElement tmpEle = elem.subnode(L"IllegalType",L"id",inttostr(cnt));
while(tmpEle.val().GetLength() > 0){//得到第一个业务类型的全部违法类型
IllegalType.Add(tmpEle.attr("name"));
if(cnt==1)
{
int m=1;
CXmlElement EleAction = tmpEle.subnode(L"IllegalAction",L"id",inttostr(m));
while(EleAction.val().GetLength() > 0)
{//得到第一个违法类型的全部违法行为和违反规定
IllegalAction.Add(EleAction.attr("name"));
DisobeyRule.Add(EleAction.attr("rule"));
IllegalCode.Add(EleAction.attr("code"));
IllegalDetail.Add(EleAction.val());
EleAction = tmpEle.subnode(L"IllegalAction",L"id",inttostr(++m));
}
}
tmpEle = elem.subnode(L"IllegalType",L"id",inttostr(++cnt));
}
}
elem = eroot.subnode(L"OperationType",L"id",inttostr(++id));
}
}
m_iRootElm.Release();
}
}
CString CXmlParse::parseManInfo(CString xmlStr)
{
if(!xmlStr.IsEmpty())
{
CString str;
VARIANT_BOOL bSuccess=false;
int xmlsize=0;
int lensxml=0;
char *tmps=new char[2048];
char *tmp=new char[200];
strcpy(tmp,"<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
for(int i=0;i < (int)strlen(tmp);i++)
xmlStr.SetAt(i,tmp[i]);
if( m_iXMLDoc->loadXML(CComBSTR(xmlStr),&bSuccess) == S_OK)
{
CString temp;
if(m_iXMLDoc->get_documentElement(&m_iRootElm) == S_OK)
{
CXmlElement eroot(m_iRootElm);
CXmlElement eResultMsg = eroot.subnode(L"resultMsg");
CString flag=eResultMsg.val();
m_iRootElm.Release();
if(flag==_T("1"))//查询结果正常
{
CXmlElement eDataMessage = eroot.subnode(L"data-message");
CXmlElement elem = eDataMessage.subnode(L"ResultSet");
CXmlElement eCols = elem.subnode(L"row",L"id",L"0");
if(eCols.val().GetLength()>0){
CXmlElement tmpNode = eCols.subnode(L"col",L"name",L"ID");
CString tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = _T("文明卡号:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"JF");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("积分:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"BUMEN");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("所属城区:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"SHANGHUNAME");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("商户名:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"SHANGHUADDRESS");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("商户地址:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"ZHIZHAONUMBER");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("执照号:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"PAIWUNUMBER");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("排污号:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"YINGYEAREA");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("营业面积:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"JINGYINGRANGE");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("营业范围:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"JINGYINGTYPE");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("经营种类:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"FAREN");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("法人:")+tempVal+_T("\r\n");
tmpNode = eCols.subnode(L"col",L"name",L"CONTACTPHONE");
tempVal = tmpNode.val();
if(tempVal == _T("null")) tempVal = _T(" ");
str = str +_T("联系电话:")+tempVal+_T("\r\n");
}
else str = _T("未查到此卡的持有者信息!");
return str;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -