2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// XMLParser.h
|
|
|
|
|
|
|
|
// Interfaces to the CXMLParser class representing the base class for XML parsing
|
|
|
|
|
|
|
|
// To use, derive a class from this base and override its OnStartElement(), OnEndElement() and OnCharacters() functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "expat/expat.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CXMLParser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CXMLParser(void);
|
|
|
|
virtual ~CXMLParser();
|
|
|
|
|
|
|
|
// The actual parsing, may be called several times; the last time needs iIsFinal == true (-> flush)
|
|
|
|
int Parse(const char * iData, size_t iLength, bool iIsFinal = false);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// LibExpat stuff:
|
|
|
|
XML_Parser mParser;
|
|
|
|
|
|
|
|
static void StartElementHandler(void * iContext, const XML_Char * iElement, const XML_Char ** iAttributes)
|
|
|
|
{
|
|
|
|
((CXMLParser *)iContext)->OnStartElement(iElement, iAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EndElementHandler (void * iContext, const XML_Char * iElement)
|
|
|
|
{
|
|
|
|
((CXMLParser *)iContext)->OnEndElement(iElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CharacterDataHandler (void * iContext, const XML_Char * iData, int iLength)
|
|
|
|
{
|
|
|
|
((CXMLParser *)iContext)->OnCharacters(iData, iLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void OnStartElement(const XML_Char * iElement, const XML_Char ** iAttributes) = 0;
|
|
|
|
virtual void OnEndElement (const XML_Char * iElement) = 0;
|
|
|
|
virtual void OnCharacters (const XML_Char * iCharacters, int iLength) = 0;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-07-29 07:13:03 -04:00
|
|
|
// The following template has been modified from code available at
|
|
|
|
// http://www.codeproject.com/Articles/1847/C-Wrappers-for-the-Expat-XML-Parser
|
|
|
|
// It uses templates to remove the virtual function call penalty (both size and speed) for each callback
|
|
|
|
|
|
|
|
/* Usage:
|
2014-07-17 10:33:09 -04:00
|
|
|
1, Declare a subclass:
|
2013-07-29 07:13:03 -04:00
|
|
|
class CMyParser : public CExpatImpl<CMyParser>
|
|
|
|
2, Declare handlers that you want in that subclass:
|
|
|
|
void CMyParser::OnEndElement(const XML_Char * iTagName);
|
|
|
|
3, Create an instance of your class:
|
|
|
|
CMyParser Parser;
|
|
|
|
4, Call Create():
|
2014-10-20 16:55:07 -04:00
|
|
|
Parser.Create(nullptr, nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
4, Call Parse(), repeatedly:
|
|
|
|
Parser.Parse(Buffer, Length);
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <class _T>
|
|
|
|
class CExpatImpl
|
|
|
|
{
|
|
|
|
|
|
|
|
// @access Constructors and destructors
|
|
|
|
public:
|
|
|
|
|
|
|
|
// @cmember General constructor
|
|
|
|
|
|
|
|
CExpatImpl ()
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
m_p = nullptr;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Destructor
|
|
|
|
|
|
|
|
~CExpatImpl ()
|
|
|
|
{
|
|
|
|
Destroy ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// @access Parser creation and deletion methods
|
|
|
|
public:
|
|
|
|
|
|
|
|
// @cmember Create a parser
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
bool Create (const XML_Char * pszEncoding = nullptr, const XML_Char * pszSep = nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
// Destroy the old parser
|
|
|
|
Destroy ();
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
// If the encoding or seperator are empty, then nullptr
|
2014-12-05 06:56:53 -05:00
|
|
|
if ((pszEncoding != nullptr) && (pszEncoding[0] == 0))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
pszEncoding = nullptr;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2014-12-05 06:56:53 -05:00
|
|
|
if ((pszSep != nullptr) && (pszSep[0] == 0))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
pszSep = nullptr;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new parser
|
2014-10-20 16:55:07 -04:00
|
|
|
m_p = XML_ParserCreate_MM (pszEncoding, nullptr, pszSep);
|
|
|
|
if (m_p == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
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 (void)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_p != nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
XML_ParserFree (m_p);
|
|
|
|
}
|
2014-10-20 16:55:07 -04:00
|
|
|
m_p = nullptr;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @cmember Parse a block of data
|
|
|
|
|
|
|
|
bool Parse (const char *pszBuffer, int nLength, bool fIsFinal = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2014-12-05 06:56:53 -05:00
|
|
|
return (XML_Parse (m_p, pszBuffer, nLength, fIsFinal) != 0);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Parse internal buffer
|
|
|
|
|
|
|
|
bool ParseBuffer (int nLength, bool fIsFinal = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_ParseBuffer (m_p, nLength, fIsFinal) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get the internal buffer
|
|
|
|
|
|
|
|
void *GetBuffer (int nLength)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_GetBuffer (m_p, nLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2015-05-09 03:25:09 -04:00
|
|
|
// Parser callback enable / disable methods:
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the start element handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableStartElementHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetStartElementHandler (m_p, fEnable ? StartElementHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the end element handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableEndElementHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetEndElementHandler (m_p, fEnable ? EndElementHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the element handlers
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableElementHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
EnableStartElementHandler (fEnable);
|
|
|
|
EnableEndElementHandler (fEnable);
|
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the character data handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableCharacterDataHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetCharacterDataHandler (m_p, fEnable ? CharacterDataHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the processing instruction handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableProcessingInstructionHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetProcessingInstructionHandler (m_p, fEnable ? ProcessingInstructionHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the comment handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableCommentHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetCommentHandler (m_p, fEnable ? CommentHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the start CDATA section handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableStartCdataSectionHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetStartCdataSectionHandler (m_p, fEnable ? StartCdataSectionHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the end CDATA section handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableEndCdataSectionHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetEndCdataSectionHandler (m_p, fEnable ? EndCdataSectionHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the CDATA section handlers
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableCdataSectionHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
EnableStartCdataSectionHandler (fEnable);
|
|
|
|
EnableEndCdataSectionHandler (fEnable);
|
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable default handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableDefaultHandler (bool fEnable = true, bool fExpand = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
if (fExpand)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
XML_SetDefaultHandlerExpand (m_p, fEnable ? DefaultHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
else
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
XML_SetDefaultHandler (m_p, fEnable ? DefaultHandler : nullptr);
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable external entity ref handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableExternalEntityRefHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetExternalEntityRefHandler (m_p, fEnable ? ExternalEntityRefHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable unknown encoding handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableUnknownEncodingHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetUnknownEncodingHandler (m_p, fEnable ? UnknownEncodingHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable start namespace handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableStartNamespaceDeclHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetStartNamespaceDeclHandler (m_p, fEnable ? StartNamespaceDeclHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable end namespace handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableEndNamespaceDeclHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetEndNamespaceDeclHandler (m_p, fEnable ? EndNamespaceDeclHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable namespace handlers
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableNamespaceDeclHandler (bool fEnable = true)
|
|
|
|
{
|
|
|
|
EnableStartNamespaceDeclHandler (fEnable);
|
|
|
|
EnableEndNamespaceDeclHandler (fEnable);
|
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the XML declaration handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableXmlDeclHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetXmlDeclHandler (m_p, fEnable ? XmlDeclHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the start DOCTYPE declaration handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableStartDoctypeDeclHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
|
|
|
XML_SetStartDoctypeDeclHandler (m_p, fEnable ? StartDoctypeDeclHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the end DOCTYPE declaration handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableEndDoctypeDeclHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2014-07-17 10:33:09 -04:00
|
|
|
XML_SetEndDoctypeDeclHandler (m_p,
|
2014-10-20 16:55:07 -04:00
|
|
|
fEnable ? EndDoctypeDeclHandler : nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// @cmember Enable / Disable the DOCTYPE declaration handler
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
void EnableDoctypeDeclHandler (bool fEnable = true)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
EnableStartDoctypeDeclHandler (fEnable);
|
|
|
|
EnableEndDoctypeDeclHandler (fEnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Parser error reporting methods
|
|
|
|
|
|
|
|
// @cmember Get last error
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
enum XML_Error GetErrorCode ()
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_GetErrorCode (m_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get the current byte index
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
long GetCurrentByteIndex ()
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_GetCurrentByteIndex (m_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get the current line number
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
int GetCurrentLineNumber ()
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_GetCurrentLineNumber (m_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get the current column number
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
int GetCurrentColumnNumber ()
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_GetCurrentColumnNumber (m_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get the current byte count
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
int GetCurrentByteCount ()
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_GetCurrentByteCount (m_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get the input context
|
|
|
|
|
|
|
|
const char *GetInputContext (int *pnOffset, int *pnSize)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
assert (m_p != nullptr);
|
2013-07-29 07:13:03 -04:00
|
|
|
return XML_GetInputContext (m_p, pnOffset, pnSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get last error string
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
const XML_LChar *GetErrorString ()
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return XML_ErrorString (GetErrorCode ());
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Return the version string
|
|
|
|
|
|
|
|
static const XML_LChar *GetExpatVersion ()
|
|
|
|
{
|
|
|
|
return XML_ExpatVersion ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get the version information
|
|
|
|
|
|
|
|
static void GetExpatVersion (int *pnMajor, int *pnMinor, int *pnMicro)
|
|
|
|
{
|
|
|
|
XML_expat_version v = XML_ExpatVersionInfo ();
|
|
|
|
if (pnMajor)
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2013-07-29 07:13:03 -04:00
|
|
|
*pnMajor = v .major;
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
if (pnMinor)
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2013-07-29 07:13:03 -04:00
|
|
|
*pnMinor = v .minor;
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
if (pnMicro)
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2013-07-29 07:13:03 -04:00
|
|
|
*pnMicro = v .micro;
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Get last error string
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
static const XML_LChar *GetErrorString (enum XML_Error nError)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return XML_ErrorString (nError);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Public handler methods:
|
|
|
|
// The template parameter should provide their own implementation for those handlers that they want
|
|
|
|
|
|
|
|
// @cmember Start element handler
|
|
|
|
|
|
|
|
void OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End element handler
|
|
|
|
|
|
|
|
void OnEndElement (const XML_Char *pszName)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Character data handler
|
|
|
|
|
|
|
|
void OnCharacterData (const XML_Char *pszData, int nLength)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Processing instruction handler
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
void OnProcessingInstruction (const XML_Char *pszTarget,
|
2013-07-29 07:13:03 -04:00
|
|
|
const XML_Char *pszData)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Comment handler
|
|
|
|
|
|
|
|
void OnComment (const XML_Char *pszData)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Start CDATA section handler
|
|
|
|
|
|
|
|
void OnStartCdataSection ()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End CDATA section handler
|
|
|
|
|
|
|
|
void OnEndCdataSection ()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Default handler
|
|
|
|
|
|
|
|
void OnDefault (const XML_Char *pszData, int nLength)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember External entity ref handler
|
|
|
|
|
|
|
|
bool OnExternalEntityRef (const XML_Char *pszContext,
|
|
|
|
const XML_Char *pszBase, const XML_Char *pszSystemID,
|
|
|
|
const XML_Char *pszPublicID)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Unknown encoding handler
|
|
|
|
|
|
|
|
bool OnUnknownEncoding (const XML_Char *pszName, XML_Encoding *pInfo)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Start namespace declaration handler
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
void OnStartNamespaceDecl (const XML_Char *pszPrefix,
|
2013-07-29 07:13:03 -04:00
|
|
|
const XML_Char *pszURI)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End namespace declaration handler
|
|
|
|
|
|
|
|
void OnEndNamespaceDecl (const XML_Char *pszPrefix)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember XML declaration handler
|
|
|
|
|
|
|
|
void OnXmlDecl (const XML_Char *pszVersion, const XML_Char *pszEncoding,
|
|
|
|
bool fStandalone)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Start DOCTYPE declaration handler
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
void OnStartDoctypeDecl (const XML_Char *pszDoctypeName,
|
2013-07-29 07:13:03 -04:00
|
|
|
const XML_Char *pszSysID, const XML_Char *pszPubID,
|
|
|
|
bool fHasInternalSubset)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End DOCTYPE declaration handler
|
|
|
|
|
|
|
|
void OnEndDoctypeDecl ()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @access Protected methods
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// @cmember Handle any post creation
|
|
|
|
|
|
|
|
void OnPostCreate ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// @access Protected static methods
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// @cmember Start element handler wrapper
|
|
|
|
|
|
|
|
static void __cdecl StartElementHandler (void *pUserData,
|
|
|
|
const XML_Char *pszName, const XML_Char **papszAttrs)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnStartElement (pszName, papszAttrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End element handler wrapper
|
|
|
|
|
|
|
|
static void __cdecl EndElementHandler (void *pUserData,
|
|
|
|
const XML_Char *pszName)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnEndElement (pszName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Character data handler wrapper
|
|
|
|
|
|
|
|
static void __cdecl CharacterDataHandler (void *pUserData,
|
|
|
|
const XML_Char *pszData, int nLength)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnCharacterData (pszData, nLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Processing instruction handler wrapper
|
|
|
|
|
|
|
|
static void __cdecl ProcessingInstructionHandler (void *pUserData,
|
|
|
|
const XML_Char *pszTarget, const XML_Char *pszData)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnProcessingInstruction (pszTarget, pszData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Comment handler wrapper
|
|
|
|
|
|
|
|
static void __cdecl CommentHandler (void *pUserData,
|
|
|
|
const XML_Char *pszData)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnComment (pszData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Start CDATA section wrapper
|
|
|
|
|
|
|
|
static void __cdecl StartCdataSectionHandler (void *pUserData)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnStartCdataSection ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End CDATA section wrapper
|
|
|
|
|
|
|
|
static void __cdecl EndCdataSectionHandler (void *pUserData)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnEndCdataSection ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Default wrapper
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
static void __cdecl DefaultHandler (void *pUserData,
|
2013-07-29 07:13:03 -04:00
|
|
|
const XML_Char *pszData, int nLength)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnDefault (pszData, nLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember External entity ref wrapper
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
static int __cdecl ExternalEntityRefHandler (void *pUserData,
|
|
|
|
const XML_Char *pszContext, const XML_Char *pszBase,
|
2013-07-29 07:13:03 -04:00
|
|
|
const XML_Char *pszSystemID, const XML_Char *pszPublicID)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
2014-07-17 10:33:09 -04:00
|
|
|
return pThis ->OnExternalEntityRef (pszContext,
|
2013-07-29 07:13:03 -04:00
|
|
|
pszBase, pszSystemID, pszPublicID) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Unknown encoding wrapper
|
|
|
|
|
|
|
|
static int __cdecl UnknownEncodingHandler (void * pUserData, const XML_Char * pszName, XML_Encoding * pInfo)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
return pThis ->OnUnknownEncoding (pszName, pInfo) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Start namespace decl wrapper
|
|
|
|
|
|
|
|
static void __cdecl StartNamespaceDeclHandler (void * pUserData, const XML_Char * pszPrefix, const XML_Char * pszURI)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnStartNamespaceDecl (pszPrefix, pszURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End namespace decl wrapper
|
|
|
|
|
|
|
|
static void __cdecl EndNamespaceDeclHandler (void * pUserData, const XML_Char * pszPrefix)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnEndNamespaceDecl (pszPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember XML declaration wrapper
|
|
|
|
|
|
|
|
static void __cdecl XmlDeclHandler (void *pUserData, const XML_Char *pszVersion, const XML_Char *pszEncoding, int nStandalone)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnXmlDecl (pszVersion, pszEncoding, nStandalone != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Start Doctype declaration wrapper
|
|
|
|
|
|
|
|
static void __cdecl StartDoctypeDeclHandler (
|
2014-07-17 10:33:09 -04:00
|
|
|
void *pUserData, const XML_Char *pszDoctypeName, const XML_Char *pszSysID,
|
2013-07-29 07:13:03 -04:00
|
|
|
const XML_Char *pszPubID, int nHasInternalSubset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
2014-07-17 10:33:09 -04:00
|
|
|
pThis ->OnStartDoctypeDecl (pszDoctypeName, pszSysID,
|
2013-07-29 07:13:03 -04:00
|
|
|
pszPubID, nHasInternalSubset != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember End Doctype declaration wrapper
|
|
|
|
|
|
|
|
static void __cdecl EndDoctypeDeclHandler (void *pUserData)
|
|
|
|
{
|
|
|
|
_T *pThis = static_cast <_T *> ((CExpatImpl <_T> *) pUserData);
|
|
|
|
pThis ->OnEndDoctypeDecl ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
XML_Parser m_p;
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns the value of the specified attribute, if found; nullptr otherwise */
|
2013-07-29 07:13:03 -04:00
|
|
|
static const XML_Char * FindAttr(const XML_Char ** iAttrs, const XML_Char * iAttrToFind)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
for (const XML_Char ** Attr = iAttrs; *Attr != nullptr; Attr += 2)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
if (strcmp(*Attr, iAttrToFind) == 0)
|
|
|
|
{
|
|
|
|
return *(Attr + 1);
|
|
|
|
}
|
|
|
|
} // for Attr - iAttrs[]
|
2014-10-20 16:55:07 -04:00
|
|
|
return nullptr;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|