159 lines
4.9 KiB
C++
159 lines
4.9 KiB
C++
#ifndef XMLDOMFILE_ZZG_2008_12_08
|
|
#define XMLDOMFILE_ZZG_2008_12_08
|
|
|
|
#include <afx.h>
|
|
#include <tchar.h>
|
|
#include "XMLDOMNode.h"
|
|
#include "msxml6.tlh"
|
|
|
|
//using namespace MSXML2;
|
|
using namespace MSXML2;
|
|
//#pragma once
|
|
//#ifdef COMMON_EXPORT
|
|
//#define COMMON_EXP __declspec( dllexport )
|
|
//#else
|
|
//#define COMMON_EXP __declspec( dllimport )
|
|
//#endif
|
|
//节点存储的信息类
|
|
class TARCH_EXP CXMLNodeInfo
|
|
{
|
|
public:
|
|
CXMLNodeInfo()
|
|
{
|
|
m_strNodeName = _T("");
|
|
m_strNodeAttributeName = _T("");
|
|
m_strNodeAttributeValue = _T("");
|
|
m_strNodeValue = _T("");
|
|
m_strNodeXPath = _T("");
|
|
m_bLeafNode = FALSE;
|
|
}
|
|
CXMLNodeInfo(const CXMLNodeInfo&info)
|
|
{
|
|
m_strNodeName = info.m_strNodeName;
|
|
m_strNodeAttributeName =info.m_strNodeAttributeName;
|
|
m_strNodeAttributeValue =info.m_strNodeAttributeValue;
|
|
m_strNodeValue = info.m_strNodeValue;
|
|
m_strNodeXPath = info.m_strNodeXPath;
|
|
m_bLeafNode = info.m_bLeafNode;
|
|
}
|
|
CXMLNodeInfo&operator=(const CXMLNodeInfo&info)
|
|
{
|
|
if (this == &info)
|
|
{
|
|
return *this;
|
|
}
|
|
m_strNodeName = info.m_strNodeName;
|
|
m_strNodeAttributeName =info.m_strNodeAttributeName;
|
|
m_strNodeAttributeValue =info.m_strNodeAttributeValue;
|
|
m_strNodeValue = info.m_strNodeValue;
|
|
m_strNodeXPath = info.m_strNodeXPath;
|
|
m_bLeafNode = info.m_bLeafNode;
|
|
return *this;
|
|
}
|
|
~CXMLNodeInfo(){}
|
|
public:
|
|
CString m_strNodeName;//节点名字
|
|
CString m_strNodeAttributeName;//节点属性名字
|
|
CString m_strNodeAttributeValue;//节点属性值
|
|
CString m_strNodeValue;//节点值(只有当为叶子节点时有值)
|
|
CString m_strNodeXPath;//节点的路径
|
|
BOOL m_bLeafNode;//是否是叶子节点
|
|
};
|
|
|
|
//节点存储的信息类
|
|
typedef std::pair<CString,CString> NodeAttriBute;
|
|
typedef Array<NodeAttriBute> NodeAttriButeAry;
|
|
class TARCH_EXP CXMLNodeInfoEx
|
|
{
|
|
public:
|
|
CXMLNodeInfoEx()
|
|
{
|
|
m_strNodeName = _T("");
|
|
//m_strNodeAttributeName = _T("");
|
|
//m_strNodeAttributeValue = _T("");
|
|
m_strNodeValue = _T("");
|
|
m_strNodeXPath = _T("");
|
|
m_bLeafNode = FALSE;
|
|
}
|
|
CXMLNodeInfoEx(const CXMLNodeInfoEx&info)
|
|
{
|
|
m_strNodeName = info.m_strNodeName;
|
|
m_aryNodeAttribute = info.m_aryNodeAttribute;
|
|
//m_strNodeAttributeName =info.m_strNodeAttributeName;
|
|
//m_strNodeAttributeValue =info.m_strNodeAttributeValue;
|
|
m_strNodeValue = info.m_strNodeValue;
|
|
m_strNodeXPath = info.m_strNodeXPath;
|
|
m_bLeafNode = info.m_bLeafNode;
|
|
}
|
|
CXMLNodeInfoEx&operator=(const CXMLNodeInfoEx&info)
|
|
{
|
|
if (this == &info)
|
|
{
|
|
return *this;
|
|
}
|
|
m_strNodeName = info.m_strNodeName;
|
|
m_aryNodeAttribute = info.m_aryNodeAttribute;
|
|
//m_strNodeAttributeName =info.m_strNodeAttributeName;
|
|
//m_strNodeAttributeValue =info.m_strNodeAttributeValue;
|
|
m_strNodeValue = info.m_strNodeValue;
|
|
m_strNodeXPath = info.m_strNodeXPath;
|
|
m_bLeafNode = info.m_bLeafNode;
|
|
return *this;
|
|
}
|
|
~CXMLNodeInfoEx(){}
|
|
public:
|
|
CString m_strNodeName;//节点名字
|
|
NodeAttriButeAry m_aryNodeAttribute;
|
|
//CString m_strNodeAttributeName;//节点属性名字
|
|
//CString m_strNodeAttributeValue;//节点属性值
|
|
CString m_strNodeValue;//节点值(只有当为叶子节点时有值)
|
|
CString m_strNodeXPath;//节点的路径
|
|
BOOL m_bLeafNode;//是否是叶子节点
|
|
};
|
|
|
|
class TARCH_EXP CXMLDOMFile
|
|
{
|
|
public:
|
|
CXMLDOMFile();
|
|
virtual ~CXMLDOMFile();
|
|
|
|
//文件是否存在
|
|
static bool IsFileExist( const TCHAR* strFileName );
|
|
//创建新的xml文档
|
|
static bool CreateNewXMLDoc(const TCHAR* strFileName,const TCHAR* strProcessingInstruction
|
|
,const TCHAR*strRootNodeName,const NodeAttriButeAry&nodeInfoAry);
|
|
//打开文件
|
|
static bool Open( const TCHAR* FileName );
|
|
//保存文件
|
|
static bool Save( const TCHAR* strSaveAsFileName = NULL );
|
|
//得到根节点指针
|
|
CXMLDOMNodePtr GetRoot( void );
|
|
//得到文件名
|
|
static TCHAR* GetXMLFileName();
|
|
//得到指定属性值的节点指针(此函数有漏洞 请根据info中存储的路径查找)
|
|
CXMLDOMNodePtr GetAssignNode(const TCHAR*szNodeName,const TCHAR*szNodeAttribute);
|
|
//得到指定节点名字的所有节点
|
|
CXMLDOMNodesPtr GetNodesByTagName(const TCHAR*szNodeName);
|
|
//选择单个节点
|
|
CXMLDOMNodePtr SelectSingleNode( const TCHAR* szNodeXPath );
|
|
//选择多个节点(/../../*)声明XPath:注意"/RootNode/Node2"是选择Node2节点,"/RootNode/Node2/*"是选择Node2下的所有子结点
|
|
CXMLDOMNodesPtr SelectNodes( const TCHAR* szNodeXPath );
|
|
// Select path for Single node by attribute name and value:
|
|
CXMLDOMNodePtr SelectNodeByAttribute( const TCHAR* szNodeXPath, const TCHAR* szAttributeName , const TCHAR* szAttributeValue );
|
|
//得到当前节点的查找路径xPath
|
|
void GetCurNodeXPath(const CXMLDOMNodePtr &pXMLDOMNodePtr,CString &strXPath);
|
|
//得到第一个属性名字构成的path
|
|
void GetNoteAttriPath(const CXMLDOMNodePtr &pXMLDOMNodePtr,const CString &strAttriName,CString &strXPath);
|
|
//是否是根节点
|
|
bool IsRootNode(const CXMLDOMNodePtr &pXMLDOMNodePtr);
|
|
//得到版本号
|
|
CString GetVersion();
|
|
//得到字符版本;
|
|
CString GetCodeVersion();
|
|
//得到当前指针
|
|
MSXML2::IXMLDOMDocument2Ptr GetPtr(){return m_pXMLDOMDocument;}
|
|
static MSXML2::IXMLDOMDocument2Ptr m_pXMLDOMDocument; // The pointer to XML Dom Document.
|
|
protected:
|
|
static TCHAR* m_strFileName; // Save opened file name .
|
|
};
|
|
#endif |