forked from organicmaps/organicmaps
Added CharData support in xml parser
This commit is contained in:
parent
a22830c77a
commit
3c9505fdff
5 changed files with 17 additions and 5 deletions
|
@ -12,8 +12,9 @@ class XmlParser : public CExpatImpl< XmlParser<DispatcherT> >
|
|||
public:
|
||||
typedef CExpatImpl< XmlParser<DispatcherT> > BaseT;
|
||||
|
||||
XmlParser(DispatcherT& dispatcher)
|
||||
: m_depth(0), m_restrictDepth(-1), m_dispatcher(dispatcher)
|
||||
XmlParser(DispatcherT& dispatcher, bool enableCharHandler = false)
|
||||
: m_depth(0), m_restrictDepth(-1), m_dispatcher(dispatcher),
|
||||
m_enableCharHandler(enableCharHandler)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -22,6 +23,8 @@ public:
|
|||
{
|
||||
// Enable all the event routines we want
|
||||
BaseT::EnableElementHandler();
|
||||
if (m_enableCharHandler)
|
||||
BaseT::EnableCharacterDataHandler();
|
||||
}
|
||||
|
||||
// Start element handler
|
||||
|
@ -55,10 +58,16 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void OnCharacterData (const XML_Char *pszData, int nLength)
|
||||
{
|
||||
m_dispatcher.CharData(string(pszData, nLength));
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_depth;
|
||||
size_t m_restrictDepth;
|
||||
DispatcherT& m_dispatcher;
|
||||
DispatcherT & m_dispatcher;
|
||||
bool m_enableCharHandler;
|
||||
};
|
||||
|
||||
#include "../../base/stop_mem_debug.hpp"
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
static const size_t KMaxXMLFileBufferSize = 16384;
|
||||
|
||||
template <typename XMLDispatcherT, typename SourceT>
|
||||
bool ParseXML(SourceT & source, XMLDispatcherT & dispatcher)
|
||||
bool ParseXML(SourceT & source, XMLDispatcherT & dispatcher, bool useCharData = false)
|
||||
{
|
||||
// Create the parser
|
||||
XmlParser<XMLDispatcherT> parser(dispatcher);
|
||||
XmlParser<XMLDispatcherT> parser(dispatcher, useCharData);
|
||||
if (!parser.Create())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ namespace ftype {
|
|||
public:
|
||||
OSMTypesStream() : m_priority(0), m_forceSkip(false) {}
|
||||
|
||||
void CharData(string const &) {}
|
||||
bool Push(string const & name)
|
||||
{
|
||||
if (!m_forceSkip && is_our_element(name))
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
bool Push(string const & name);
|
||||
void AddAttr(string const & name, string const & value);
|
||||
void Pop(string const &);
|
||||
void CharData(string const &) {}
|
||||
|
||||
protected:
|
||||
virtual void EmitElement(XMLElement * p) = 0;
|
||||
|
|
|
@ -118,6 +118,7 @@ namespace yg
|
|||
bool Push(string const & element);
|
||||
void Pop(string const & element);
|
||||
void AddAttr(string const & attribute, string const & value);
|
||||
void CharData(string const &) {}
|
||||
|
||||
void popCharStyle();
|
||||
void popGlyphInfo();
|
||||
|
|
Loading…
Add table
Reference in a new issue