14 #include "expat/expat.h"
27 int Parse(
const char * iData,
size_t iLength,
bool iIsFinal =
false);
33 static void StartElementHandler(
void * iContext,
const XML_Char * iElement,
const XML_Char ** iAttributes)
35 ((
CXMLParser *)iContext)->OnStartElement(iElement, iAttributes);
40 ((
CXMLParser *)iContext)->OnEndElement(iElement);
45 ((
CXMLParser *)iContext)->OnCharacters(iData, iLength);
49 virtual void OnStartElement(
const XML_Char * iElement,
const XML_Char ** iAttributes) = 0;
51 virtual void OnCharacters (
const XML_Char * iCharacters,
int iLength) = 0;
102 bool Create (
const XML_Char * pszEncoding =
nullptr,
const XML_Char * pszSep =
nullptr)
108 if ((pszEncoding !=
nullptr) && (pszEncoding[0] == 0))
110 pszEncoding =
nullptr;
112 if ((pszSep !=
nullptr) && (pszSep[0] == 0))
118 m_p = XML_ParserCreate_MM (pszEncoding,
nullptr, pszSep);
125 _T * pThis =
static_cast <_T *
> (
this);
126 pThis ->OnPostCreate ();
129 XML_SetUserData (
m_p, (
void *)
this);
139 XML_ParserFree (
m_p);
147 bool Parse (
const char *pszBuffer,
int nLength,
bool fIsFinal =
true)
149 assert (
m_p !=
nullptr);
150 return (XML_Parse (
m_p, pszBuffer, nLength, fIsFinal) != 0);
157 assert (
m_p !=
nullptr);
158 return XML_ParseBuffer (
m_p, nLength, fIsFinal) != 0;
165 assert (
m_p !=
nullptr);
166 return XML_GetBuffer (
m_p, nLength);
177 assert (
m_p !=
nullptr);
185 assert (
m_p !=
nullptr);
193 assert (
m_p !=
nullptr);
202 assert (
m_p !=
nullptr);
210 assert (
m_p !=
nullptr);
218 assert (
m_p !=
nullptr);
226 assert (
m_p !=
nullptr);
234 assert (
m_p !=
nullptr);
242 assert (
m_p !=
nullptr);
251 assert (
m_p !=
nullptr);
266 assert (
m_p !=
nullptr);
274 assert (
m_p !=
nullptr);
282 assert (
m_p !=
nullptr);
290 assert (
m_p !=
nullptr);
306 assert (
m_p !=
nullptr);
314 assert (
m_p !=
nullptr);
322 assert (
m_p !=
nullptr);
323 XML_SetEndDoctypeDeclHandler (
m_p,
331 assert (
m_p !=
nullptr);
343 assert (
m_p !=
nullptr);
344 return XML_GetErrorCode (
m_p);
351 assert (
m_p !=
nullptr);
352 return XML_GetCurrentByteIndex (
m_p);
359 assert (
m_p !=
nullptr);
360 return XML_GetCurrentLineNumber (
m_p);
367 assert (
m_p !=
nullptr);
368 return XML_GetCurrentColumnNumber (
m_p);
375 assert (
m_p !=
nullptr);
376 return XML_GetCurrentByteCount (
m_p);
383 assert (
m_p !=
nullptr);
384 return XML_GetInputContext (
m_p, pnOffset, pnSize);
398 return XML_ExpatVersion ();
405 XML_expat_version v = XML_ExpatVersionInfo ();
424 return XML_ErrorString (nError);
455 const XML_Char *pszData)
491 const XML_Char *pszBase,
const XML_Char *pszSystemID,
492 const XML_Char *pszPublicID)
507 const XML_Char *pszURI)
521 void OnXmlDecl (
const XML_Char *pszVersion,
const XML_Char *pszEncoding,
530 const XML_Char *pszSysID,
const XML_Char *pszPubID,
531 bool fHasInternalSubset)
558 const XML_Char *pszName,
const XML_Char **papszAttrs)
561 pThis ->OnStartElement (pszName, papszAttrs);
567 const XML_Char *pszName)
570 pThis ->OnEndElement (pszName);
576 const XML_Char *pszData,
int nLength)
579 pThis ->OnCharacterData (pszData, nLength);
585 const XML_Char *pszTarget,
const XML_Char *pszData)
588 pThis ->OnProcessingInstruction (pszTarget, pszData);
594 const XML_Char *pszData)
597 pThis ->OnComment (pszData);
605 pThis ->OnStartCdataSection ();
613 pThis ->OnEndCdataSection ();
619 const XML_Char *pszData,
int nLength)
622 pThis ->OnDefault (pszData, nLength);
628 const XML_Char *pszContext,
const XML_Char *pszBase,
629 const XML_Char *pszSystemID,
const XML_Char *pszPublicID)
632 return pThis ->OnExternalEntityRef (pszContext,
633 pszBase, pszSystemID, pszPublicID) ? 1 : 0;
641 return pThis ->OnUnknownEncoding (pszName, pInfo) ? 1 : 0;
649 pThis ->OnStartNamespaceDecl (pszPrefix, pszURI);
657 pThis ->OnEndNamespaceDecl (pszPrefix);
662 static void __cdecl
XmlDeclHandler (
void *pUserData,
const XML_Char *pszVersion,
const XML_Char *pszEncoding,
int nStandalone)
665 pThis ->OnXmlDecl (pszVersion, pszEncoding, nStandalone != 0);
671 void *pUserData,
const XML_Char *pszDoctypeName,
const XML_Char *pszSysID,
672 const XML_Char *pszPubID,
int nHasInternalSubset
676 pThis ->OnStartDoctypeDecl (pszDoctypeName, pszSysID,
677 pszPubID, nHasInternalSubset != 0);
685 pThis ->OnEndDoctypeDecl ();
694 static const XML_Char *
FindAttr(
const XML_Char ** iAttrs,
const XML_Char * iAttrToFind)
696 for (
const XML_Char ** Attr = iAttrs; *Attr !=
nullptr; Attr += 2)
698 if (strcmp(*Attr, iAttrToFind) == 0)
static void StartElementHandler(void *iContext, const XML_Char *iElement, const XML_Char **iAttributes)
virtual void OnStartElement(const XML_Char *iElement, const XML_Char **iAttributes)=0
static void EndElementHandler(void *iContext, const XML_Char *iElement)
virtual void OnCharacters(const XML_Char *iCharacters, int iLength)=0
virtual void OnEndElement(const XML_Char *iElement)=0
int Parse(const char *iData, size_t iLength, bool iIsFinal=false)
static void CharacterDataHandler(void *iContext, const XML_Char *iData, int iLength)
static void __cdecl ProcessingInstructionHandler(void *pUserData, const XML_Char *pszTarget, const XML_Char *pszData)
static void __cdecl CharacterDataHandler(void *pUserData, const XML_Char *pszData, int nLength)
void EnableStartDoctypeDeclHandler(bool fEnable=true)
static void __cdecl EndNamespaceDeclHandler(void *pUserData, const XML_Char *pszPrefix)
bool OnUnknownEncoding(const XML_Char *pszName, XML_Encoding *pInfo)
void EnableStartElementHandler(bool fEnable=true)
void OnDefault(const XML_Char *pszData, int nLength)
static const XML_LChar * GetErrorString(enum XML_Error nError)
void EnableDoctypeDeclHandler(bool fEnable=true)
void EnableStartCdataSectionHandler(bool fEnable=true)
static void __cdecl StartElementHandler(void *pUserData, const XML_Char *pszName, const XML_Char **papszAttrs)
void EnableEndCdataSectionHandler(bool fEnable=true)
bool ParseBuffer(int nLength, bool fIsFinal=true)
void OnComment(const XML_Char *pszData)
void OnProcessingInstruction(const XML_Char *pszTarget, const XML_Char *pszData)
bool OnExternalEntityRef(const XML_Char *pszContext, const XML_Char *pszBase, const XML_Char *pszSystemID, const XML_Char *pszPublicID)
static void __cdecl DefaultHandler(void *pUserData, const XML_Char *pszData, int nLength)
void OnEndNamespaceDecl(const XML_Char *pszPrefix)
void EnableCommentHandler(bool fEnable=true)
static int __cdecl UnknownEncodingHandler(void *pUserData, const XML_Char *pszName, XML_Encoding *pInfo)
static void __cdecl StartCdataSectionHandler(void *pUserData)
void OnStartCdataSection()
static void __cdecl StartNamespaceDeclHandler(void *pUserData, const XML_Char *pszPrefix, const XML_Char *pszURI)
static void __cdecl CommentHandler(void *pUserData, const XML_Char *pszData)
static int __cdecl ExternalEntityRefHandler(void *pUserData, const XML_Char *pszContext, const XML_Char *pszBase, const XML_Char *pszSystemID, const XML_Char *pszPublicID)
void OnStartNamespaceDecl(const XML_Char *pszPrefix, const XML_Char *pszURI)
void EnableEndDoctypeDeclHandler(bool fEnable=true)
bool Create(const XML_Char *pszEncoding=nullptr, const XML_Char *pszSep=nullptr)
void EnableUnknownEncodingHandler(bool fEnable=true)
void EnableExternalEntityRefHandler(bool fEnable=true)
void EnableDefaultHandler(bool fEnable=true, bool fExpand=true)
void EnableNamespaceDeclHandler(bool fEnable=true)
static void __cdecl StartDoctypeDeclHandler(void *pUserData, const XML_Char *pszDoctypeName, const XML_Char *pszSysID, const XML_Char *pszPubID, int nHasInternalSubset)
void OnXmlDecl(const XML_Char *pszVersion, const XML_Char *pszEncoding, bool fStandalone)
static void __cdecl EndDoctypeDeclHandler(void *pUserData)
static void __cdecl XmlDeclHandler(void *pUserData, const XML_Char *pszVersion, const XML_Char *pszEncoding, int nStandalone)
void OnStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
void EnableCharacterDataHandler(bool fEnable=true)
int GetCurrentByteCount()
void OnStartDoctypeDecl(const XML_Char *pszDoctypeName, const XML_Char *pszSysID, const XML_Char *pszPubID, bool fHasInternalSubset)
static const XML_Char * FindAttr(const XML_Char **iAttrs, const XML_Char *iAttrToFind)
Returns the value of the specified attribute, if found; nullptr otherwise.
const char * GetInputContext(int *pnOffset, int *pnSize)
bool Parse(const char *pszBuffer, int nLength, bool fIsFinal=true)
int GetCurrentColumnNumber()
static const XML_LChar * GetExpatVersion()
void OnEndElement(const XML_Char *pszName)
long GetCurrentByteIndex()
static void __cdecl EndCdataSectionHandler(void *pUserData)
int GetCurrentLineNumber()
void OnCharacterData(const XML_Char *pszData, int nLength)
void EnableStartNamespaceDeclHandler(bool fEnable=true)
static void GetExpatVersion(int *pnMajor, int *pnMinor, int *pnMicro)
void EnableEndElementHandler(bool fEnable=true)
void EnableElementHandler(bool fEnable=true)
void EnableCdataSectionHandler(bool fEnable=true)
static void __cdecl EndElementHandler(void *pUserData, const XML_Char *pszName)
void EnableProcessingInstructionHandler(bool fEnable=true)
void EnableEndNamespaceDeclHandler(bool fEnable=true)
void * GetBuffer(int nLength)
enum XML_Error GetErrorCode()
const XML_LChar * GetErrorString()
void EnableXmlDeclHandler(bool fEnable=true)