#ifndef DSSI_EXPATIMPL_H
#define DSSI_EXPATIMPL_H
//-----------------------------------------------------------------------------
//
// @doc
//
// @module ExpatImpl.h - Expat class container |
//
// This module contains the definition of the expat class container.
//
// Copyright (c) 1994-2002 - Descartes Systems Sciences, Inc.
//
// @end
//
// $History: ExpatImpl.h $
//
// ***************** Version 1 *****************
// User: Tim Smith Date: 1/29/02 Time: 1:57p
// Created in $/Omni_V2/_ToolLib
// 1. String.h now replaced with StringCode.h.
// 2. StringRsrc.h modified to use new string class.
// 3. Added tons of new classes from the wedge work.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// Required include files
//
//-----------------------------------------------------------------------------
#include <assert.h>
#include "expat.h"
//-----------------------------------------------------------------------------
//
// Forward definitions
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// Template class definition
//
//-----------------------------------------------------------------------------
template <class _T>
class CExpatImpl
{
// @access Constructors and destructors
public:
// @cmember General constructor
CExpatImpl ()
{
m_p = NULL;
}
// @cmember Destructor
~CExpatImpl ()
{
Destroy ();
}
// @access Parser creation and deletion methods
public:
// @cmember Create a parser
bool Create (const XML_Char *pszEncoding = NULL,
const XML_Char *pszSep = NULL)
{
//
// Destroy the old parser
//
Destroy ();
//
// If the encoding or seperator are empty, then NULL
//
if (pszEncoding != NULL && pszEncoding [0] == 0)
pszEncoding = NULL;
if (pszSep != NULL && pszSep [0] == 0)
pszSep = NULL;
//
// Create the new one
//
m_p = XML_ParserCreate_MM (pszEncoding, NULL, pszSep);
if (m_p == NULL)
return false;
//
// Invoke the post create routine
//
_T *pThis = static_cast <_T *> (this);
pThis ->OnPostCreate ();
//
// Set the user data used in callbacks
//
XML_SetUserData (m_p, (void *) this);
return true;
}
// @cmember Destroy the parser
void Destroy ()
{
if (m_p != NULL)
XML_ParserFree (m_p);
m_p = NULL;
}
// @access Parser parse methods
public:
// @cmember Parse a block of data
bool Parse (const char *pszBuffer, int nLength = -1, bool fIsFinal = true)
{
//
// Validate
//
assert (m_p != NULL);
//
// Get the length if not specified
//
if (nLength < 0)
nLength = strlen (pszBuffer);
//
// Invoke the parser
//
return XML_Parse (m_p, pszBuffer, nLength, fIsFinal) != 0;
}
// @cmember Parse a block of data
#ifdef WCHAR
bool Parse (const WCHAR *pszBuffer, int nLength = -1, bool fIsFinal = true)
{
//
// Validate
//
assert (m_p != NULL);
//
// Get the length if not specified
//
if (nLength < 0)
nLength = wcslen (pszBuffer) * 2;
//
// Invoke the parser
//
return XML_Parse (m_p, pszBuffer, nLength, fIsFinal) != 0;
}
#endif
// @cmember Parse internal buffer
bool ParseBuffer (int nLength, bool fIsFinal = true)
{
assert (m_p != NULL);
return XML_ParseBuffer (m_p, nLength, fIsFinal) != 0;
}
// @cmember Get the internal buffer
void *GetBuffer (int nLength)
{
assert (m_p != NULL);
return XML_GetBuffer (m_p, nLength);
}
// @access Parser callback enable/disable methods
public:
// @cmember Enable/Disable the start element handler
void EnableStartElementHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetStartElementHandler (m_p, fEnable ? StartElementHandler : NULL);
}
// @cmember Enable/Disable the end element handler
void EnableEndElementHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetEndElementHandler (m_p, fEnable ? EndElementHandler : NULL);
}
// @cmember Enable/Disable the element handlers
void EnableElementHandler (bool fEnable = true)
{
assert (m_p != NULL);
EnableStartElementHandler (fEnable);
EnableEndElementHandler (fEnable);
}
// @cmember Enable/Disable the character data handler
void EnableCharacterDataHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetCharacterDataHandler (m_p,
fEnable ? CharacterDataHandler : NULL);
}
// @cmember Enable/Disable the processing instruction handler
void EnableProcessingInstructionHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetProcessingInstructionHandler (m_p,
fEnable ? ProcessingInstructionHandler : NULL);
}
// @cmember Enable/Disable the comment handler
void EnableCommentHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetCommentHandler (m_p, fEnable ? CommentHandler : NULL);
}
// @cmember Enable/Disable the start CDATA section handler
void EnableStartCdataSectionHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetStartCdataSectionHandler (m_p,
fEnable ? StartCdataSectionHandler : NULL);
}
// @cmember Enable/Disable the end CDATA section handler
void EnableEndCdataSectionHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetEndCdataSectionHandler (m_p,
fEnable ? EndCdataSectionHandler : NULL);
}
// @cmember Enable/Disable the CDATA section handlers
void EnableCdataSectionHandler (bool fEnable = true)
{
assert (m_p != NULL);
EnableStartCdataSectionHandler (fEnable);
EnableEndCdataSectionHandler (fEnable);
}
// @cmember Enable/Disable default handler
void EnableDefaultHandler (bool fEnable = true, bool fExpand = true)
{
assert (m_p != NULL);
if (fExpand)
{
XML_SetDefaultHandlerExpand (m_p,
fEnable ? DefaultHandler : NULL);
}
else
XML_SetDefaultHandler (m_p, fEnable ? DefaultHandler : NULL);
}
// @cmember Enable/Disable external entity ref handler
void EnableExternalEntityRefHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetExternalEntityRefHandler (m_p,
fEnable ? ExternalEntityRefHandler : NULL);
}
// @cmember Enable/Disable unknown encoding handler
void EnableUnknownEncodingHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetUnknownEncodingHandler (m_p,
fEnable ? UnknownEncodingHandler : NULL);
}
// @cmember Enable/Disable start namespace handler
void EnableStartNamespaceDeclHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetStartNamespaceDeclHandler (m_p,
fEnable ? StartNamespaceDeclHandler : NULL);
}
// @cmember Enable/Disable end namespace handler
void EnableEndNamespaceDeclHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetEndNamespaceDeclHandler (m_p,
fEnable ? EndNamespaceDeclHandler : NULL);
}
// @cmember Enable/Disable namespace handlers
void EnableNamespaceDeclHandler (bool fEnable = true)
{
EnableStartNamespaceDeclHandler (fEnable);
EnableEndNamespaceDeclHandler (fEnable);
}
// @cmember Enable/Disable the XML declaration handler
void EnableXmlDeclHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetXmlDeclHandler (m_p, fEnable ? XmlDeclHandler : NULL);
}
// @cmember Enable/Disable the start DOCTYPE declaration handler
void EnableStartDoctypeDeclHandler (bool fEnable = true)
{
assert (m_p != NULL);
XML_SetStartDoctypeDeclHandler (m_p,
fEnable ? StartDoctypeDeclHandler : NULL);
}
// @cmember Enable/Disable the end DOCTYPE declaration handler
Expat解析XML
5星 · 超过95%的资源 需积分: 9 191 浏览量
2008-06-15
11:56:47
上传
评论
收藏 516KB RAR 举报
C罗123
- 粉丝: 3
- 资源: 28
最新资源
- 海信智能电视刷机数据 LED42K330X3D(0000) 生产用软件数据 务必确认机编一致 强制刷机 整机USB升级程序
- shujudaochuceshi
- learn-ruby.zip
- test111111111111111111
- face-detect.ipynb
- 以下是一些关于ACM(国际大学生程序设计竞赛)、NOI(全国青少年信息学奥林匹克竞赛)以及CSP(全国青少年信息学奥林匹克竞赛提
- 是一些电子设计竞赛(电赛)经验分享,包括备赛策略、项目管理、团队合作和比赛期间的注意事项
- 全能运行库修复工具DirectX Repair v4.1.0.30770
- las格式点云数据使用详解(附VS编译好的LAStools工具)
- KRPano插件一键解密大师1.4.0 (解压密码1234)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈