SAXcharacters needs to close cdata sections

This commit is contained in:
Stefan Radomski 2013-08-17 20:36:52 +02:00
parent 824e8abc95
commit 8f8db494ba
2 changed files with 19 additions and 1 deletions

View file

@ -48,6 +48,7 @@ class libxml2_base
virtual void SAXendDocument() = 0; virtual void SAXendDocument() = 0;
virtual void SAXlocator(xmlSAXLocatorPtr locator) = 0; virtual void SAXlocator(xmlSAXLocatorPtr locator) = 0;
virtual void SAXcharacters(const xmlChar* ch, int len) = 0; virtual void SAXcharacters(const xmlChar* ch, int len) = 0;
virtual void SAXcdata(const xmlChar* ch, int len) = 0;
virtual void SAXignorableWhitespace(const xmlChar* ch, int len) = 0; virtual void SAXignorableWhitespace(const xmlChar* ch, int len) = 0;
virtual void SAXwarning(const std::string& warning) = 0; virtual void SAXwarning(const std::string& warning) = 0;
virtual void SAXerror(const std::string& error) = 0; virtual void SAXerror(const std::string& error) = 0;
@ -194,6 +195,7 @@ class libxml2_wrapper :
virtual void SAXendDocument(); virtual void SAXendDocument();
virtual void SAXlocator(xmlSAXLocatorPtr locator) { locator_ = locator; } virtual void SAXlocator(xmlSAXLocatorPtr locator) { locator_ = locator; }
virtual void SAXcharacters(const xmlChar* ch, int len); virtual void SAXcharacters(const xmlChar* ch, int len);
virtual void SAXcdata(const xmlChar* ch, int len);
virtual void SAXignorableWhitespace(const xmlChar* ch, int len); virtual void SAXignorableWhitespace(const xmlChar* ch, int len);
virtual void SAXwarning(const std::string& warning); virtual void SAXwarning(const std::string& warning);
virtual void SAXerror(const std::string& error); virtual void SAXerror(const std::string& error);
@ -505,10 +507,20 @@ void libxml2_wrapper<string_type, T0, T1>::SAXendDocument()
template<class string_type, class T0, class T1> template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXcharacters(const xmlChar* ch, int len) void libxml2_wrapper<string_type, T0, T1>::SAXcharacters(const xmlChar* ch, int len)
{ {
if(isInCData_)
SAXendCdataSection();
if(contentHandler_) if(contentHandler_)
contentHandler_->characters(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(ch), len)); contentHandler_->characters(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(ch), len));
} // SAXcharacters } // SAXcharacters
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXcdata(const xmlChar* ch, int len)
{
if(contentHandler_)
contentHandler_->characters(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(ch), len));
} // SAXcdata
template<class string_type, class T0, class T1> template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXignorableWhitespace(const xmlChar* ch, int len) void libxml2_wrapper<string_type, T0, T1>::SAXignorableWhitespace(const xmlChar* ch, int len)
{ {
@ -561,6 +573,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXcomment(const xmlChar* comment)
template<class string_type, class T0, class T1> template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXstartCdataSection() void libxml2_wrapper<string_type, T0, T1>::SAXstartCdataSection()
{ {
if (isInCData_)
return;
isInCData_ = true; isInCData_ = true;
if(lexicalHandler_) if(lexicalHandler_)
lexicalHandler_->startCDATA(); lexicalHandler_->startCDATA();
@ -569,6 +584,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXstartCdataSection()
template<class string_type, class T0, class T1> template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXendCdataSection() void libxml2_wrapper<string_type, T0, T1>::SAXendCdataSection()
{ {
if (!isInCData_)
return;
if(lexicalHandler_) if(lexicalHandler_)
lexicalHandler_->endCDATA(); lexicalHandler_->endCDATA();
isInCData_ = false; isInCData_ = false;

View file

@ -62,7 +62,7 @@ void lwit_cdata(void* user_data, const xmlChar* ch, int len)
{ {
libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data); libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data);
p->SAXstartCdataSection(); p->SAXstartCdataSection();
p->SAXcharacters(ch, len); p->SAXcdata(ch, len);
// everyone else will call endCData if we are in cdata // everyone else will call endCData if we are in cdata
// p->SAXendCdataSection(); // p->SAXendCdataSection();
} // lwit_cdata } // lwit_cdata