📄 node.h
字号:
#pragma once
#import "msxml4.dll" named_guids
///////////////////////////////////////////////////////////////////////////////
//
// CNodeException
//
///////////////////////////////////////////////////////////////////////////////
class CNodeException
{
public:
typedef enum
{
eError1,
eError2
} ECode;
CNodeException(int nCode, const CString& sMessage);
int GetCode();
CString GetMessage();
protected:
int m_nCode;
CString m_sMessage;
};
///////////////////////////////////////////////////////////////////////////////
//
// CFragmentCollection
//
///////////////////////////////////////////////////////////////////////////////
class CFragmentCollection
{
public:
static MSXML2::IXMLDOMDocument2Ptr GetDocument();
static MSXML2::IXMLDOMNodePtr CreateFragment();
static void CheckDocumentCounter();
protected:
static MSXML2::IXMLDOMDocument2Ptr m_spDocument;
static MSXML2::IXMLDOMDocumentFragmentPtr m_spFragment;
static int m_nTmpNameCounter;
};
///////////////////////////////////////////////////////////////////////////////
//
// CNode
//
///////////////////////////////////////////////////////////////////////////////
class CNode
{
public:
typedef enum {
Element,
Attribute
} ENodeType;
protected:
CNode();
CNode(CNode& rParentNode, MSXML2::IXMLDOMNodePtr spThisNode);
CNode(MSXML2::IXMLDOMDocument2Ptr& rspDocument);
public:
virtual ~CNode();
CString Transform(const CString& sXSLTFilename);
CString GetNodeName() const { return (LPCTSTR)m_spNode->nodeName; }
CString GetNodeText() const { return (LPCTSTR)m_spNode->text; }
CString ToXMLString() const { return (LPCTSTR)m_spNode->xml; }
protected:
friend class CDoc;
void DeclareNamespace(const CString& sPrefix, const CString& sURI);
MSXML2::IXMLDOMNodePtr CreateNode(ENodeType eNodeType, const CString& sNamespaceURI, LPCTSTR szName);
bool CompareChildName( MSXML2::IXMLDOMNodePtr spChild, const CString& sNamespaceURI, const CString& sName );
int ChildCount(ENodeType eNodeType, const CString& sNamespaceURI, const CString& sName);
MSXML2::IXMLDOMNodePtr AppendChild(ENodeType eNodeType, const CString& sNamespaceURI, const CString& sName, const CString& sValue);
MSXML2::IXMLDOMNodePtr AppendChildAttribute(MSXML2::IXMLDOMNodePtr spNode, const CString& sNamespaceURI, const CString& sName, const CString& sValue);
MSXML2::IXMLDOMNodePtr AppendChildElement(const CString& sNamespaceURI, const CString& sElement, CNode* pNode, MSXML2::IXMLDOMNodePtr spHostNode = MSXML2::IXMLDOMNodePtr());
MSXML2::IXMLDOMNodePtr RemoveChildAt(ENodeType eNodeType, const CString& sNamespaceURI, const CString& sName, int nIndex);
MSXML2::IXMLDOMNodePtr ReplaceChildAt(ENodeType eNodeType, const CString& sNamespaceURI, const CString& sName, int nIndex, const CString& sValue);
MSXML2::IXMLDOMNodePtr GetChildAt(ENodeType eNodeType, const CString& sNamespaceURI, const CString& sName, int nIndex);
MSXML2::IXMLDOMNodePtr SetChild(ENodeType eNodeType, const CString& sNamespaceURI, const CString& sName, const CString& sValue);
MSXML2::IXMLDOMDocument2Ptr m_spDocument;
MSXML2::IXMLDOMNodePtr m_spNode;
};
///////////////////////////////////////////////////////////////////////////////
//
// CDoc
//
///////////////////////////////////////////////////////////////////////////////
class CDoc
{
public:
MSXML2::IXMLDOMDocument2Ptr Load(const CString& sFilename);
void SetRootElementName(CString sName, CString sNamespaceURI);
void SetSchemaLocation(const CString& sSchemaLocation);
void Save(const CString& sFilename, CNode& rNode);
void Validate(CNode& rNode);
protected:
void FinalizeRootElement(CNode& rNode);
void InternalSetSchemaLocation(CNode& rNode);
virtual void DeclareNamespaces(CNode& rNode) = 0;
void DeclareNamespace(CNode& rNode, const CString& sPrefix, const CString& sURI)
{
rNode.DeclareNamespace(sPrefix, sURI);
}
CString m_sName;
CString m_sNamespaceURI;
CString m_sSchemaLocation;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaType
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaType
{
public:
enum {
WHITESPACE_PRESERVE,
WHITESPACE_REPLACE,
WHITESPACE_COLLAPSE
};
virtual operator CString() = 0;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaBoolean
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaBoolean : public CSchemaType
{
public:
CSchemaBoolean(bool bValue) { m_Value = bValue; }
CSchemaBoolean(const CString& sValue) { m_Value = (sValue == _T("true") || sValue == _T("1")); }
virtual operator bool() { return m_Value; }
virtual operator CString() { return m_Value ? _T("true") : _T("false"); }
typedef bool basetype;
protected:
bool m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaFloat (32bit floating point number)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaFloat : public CSchemaType
{
public:
CSchemaFloat(float fValue) { m_Value = fValue; }
CSchemaFloat(const CString& sValue) { _stscanf(sValue, _T("%G"), &m_Value); }
virtual operator float() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 32, _T("%G"), m_Value); return szValue; }
typedef float basetype;
protected:
float m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaDouble (64bit floating point number)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaDouble : public CSchemaType
{
public:
CSchemaDouble(double fValue) { m_Value = fValue; }
CSchemaDouble(const CString& sValue) { _stscanf(sValue, _T("%lG"), &m_Value); }
virtual operator double() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 32, _T("%lG"), m_Value); return szValue; }
typedef double basetype;
protected:
double m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CDecimal
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaDecimal : public CSchemaType
{
public:
CSchemaDecimal(double fValue) { m_Value = fValue; }
CSchemaDecimal(const CString& sValue) { _stscanf(sValue, _T("%lG"), &m_Value); }
virtual operator double() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 32, _T("%lG"), m_Value); return szValue; }
typedef double basetype;
protected:
double m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaLong (signed 64bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaLong : public CSchemaType
{
public:
CSchemaLong(__int64 nValue) { m_Value = nValue; }
CSchemaLong(const CString& sValue) { m_Value = _ttoi64(sValue); }
virtual operator __int64() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%I64i"), m_Value); szValue[31] = 0; return szValue; }
typedef __int64 basetype;
protected:
__int64 m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaUnsignedLong (unsigned 64bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaUnsignedLong : public CSchemaType
{
public:
CSchemaUnsignedLong(unsigned __int64 nValue) { m_Value = nValue; }
CSchemaUnsignedLong(const CString& sValue) { m_Value = _ttoi64(sValue); }
virtual operator unsigned __int64() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%I64u"), m_Value); szValue[31] = 0; return szValue; }
typedef unsigned __int64 basetype;
protected:
unsigned __int64 m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaInt (signed 32bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaInt : public CSchemaType
{
public:
CSchemaInt(long nValue) { m_Value = nValue; }
CSchemaInt(const CString& sValue) { m_Value = _ttol(sValue); }
virtual operator long() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%li"), m_Value); szValue[31] = 0; return szValue; }
typedef long basetype;
protected:
long m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaUnsignedInt (unsigned 32bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaUnsignedInt : public CSchemaType
{
public:
CSchemaUnsignedInt(unsigned long nValue) { m_Value = nValue; }
CSchemaUnsignedInt(const CString& sValue) { m_Value = _ttol(sValue); }
virtual operator unsigned long() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%lu"), m_Value); szValue[31] = 0; return szValue; }
typedef unsigned long basetype;
protected:
unsigned long m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaShort (signed 16bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaShort : public CSchemaType
{
public:
CSchemaShort(short nValue) { m_Value = nValue; }
CSchemaShort(const CString& sValue) { m_Value = _ttoi(sValue); }
virtual operator short() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%hi"), m_Value); szValue[31] = 0; return szValue; }
typedef short basetype;
protected:
short m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaUnsignedShort (unsigned 16bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaUnsignedShort : public CSchemaType
{
public:
CSchemaUnsignedShort(unsigned short nValue) { m_Value = nValue; }
CSchemaUnsignedShort(const CString& sValue) { m_Value = _ttoi(sValue); }
virtual operator unsigned short() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%hu"), m_Value); szValue[31] = 0; return szValue; }
typedef unsigned short basetype;
protected:
unsigned short m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaByte (signed 8bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaByte : public CSchemaType
{
public:
CSchemaByte(char nValue) { m_Value = nValue; }
CSchemaByte(const CString& sValue) { m_Value = _ttoi(sValue); }
virtual operator char() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%hi"), m_Value); szValue[31] = 0; return szValue; }
typedef char basetype;
protected:
char m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaUnsignedShort (unsigned 16bit integer)
//
///////////////////////////////////////////////////////////////////////////////
class CSchemaUnsignedByte : public CSchemaType
{
public:
CSchemaUnsignedByte(unsigned char nValue) { m_Value = nValue; }
CSchemaUnsignedByte(const CString& sValue) { m_Value = _ttoi(sValue); }
virtual operator unsigned char() { return m_Value; }
virtual operator CString() { TCHAR szValue[32]; _sntprintf(szValue, 31, _T("%hu"), m_Value); szValue[31] = 0; return szValue; }
typedef unsigned char basetype;
protected:
unsigned char m_Value;
};
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaInteger
// CSchemaNegativeInteger
// CSchemaNonNegativeInteger
// CSchemaPositiveInteger
// CSchemaNonPositiveInteger
//
///////////////////////////////////////////////////////////////////////////////
typedef CSchemaLong CSchemaInteger;
typedef CSchemaInteger CSchemaNegativeInteger;
typedef CSchemaInteger CSchemaNonNegativeInteger;
typedef CSchemaInteger CSchemaPositiveInteger;
typedef CSchemaInteger CSchemaNonPositiveInteger;
///////////////////////////////////////////////////////////////////////////////
//
// CSchemaString family
//
///////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -