Skip to content

Commit

Permalink
Make it compatible with libxml2 >= 2.12.0
Browse files Browse the repository at this point in the history
* libxml++/document.cc:
* libxml++/dtd.cc:
* libxml++/nodes/entitydeclaration.cc:
* libxml++/nodes/entityreference.cc:
* libxml++/validators/relaxngvalidator.cc: Modify #include directives.
* libxml++/keepblanks.cc: Ignore deprecation of xmlKeepBlanksDefault().
* tests/saxparser_chunk_parsing_inconsistent_state/main.cc:
Accept that MySaxParser::on_start_document() can be called before
MySaxParser::on_error().
  • Loading branch information
kjellahl committed Nov 18, 2023
1 parent 5f53717 commit 4947181
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions libxml++/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <libxml/tree.h>
#include <libxml/xinclude.h>
#include <libxml/xmlsave.h>
#include <libxml/parser.h> // XML_PARSE_NOXINCNODE, XML_PARSE_NOBASEFIX

#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion libxml++/dtd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <libxml++/exceptions/parse_error.h>
#include <libxml++/io/istreamparserinputbuffer.h>

#include <libxml/tree.h>
#include <libxml/parser.h>

#include <sstream>

Expand Down
5 changes: 4 additions & 1 deletion libxml++/keepblanks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* included with libxml++ as the file COPYING.
*/

#include <libxml++/keepblanks.h>
// xmlKeepBlanksDefault() is deprecated since libxml2 2.12.0.
// Ignore deprecations here.
#define XML_DEPRECATED

#include <libxml++/keepblanks.h>
#include <libxml/globals.h>

namespace xmlpp
Expand Down
2 changes: 1 addition & 1 deletion libxml++/nodes/entitydeclaration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include <libxml++/nodes/entitydeclaration.h>
#include <libxml/tree.h>
#include <libxml/entities.h>

namespace xmlpp
{
Expand Down
2 changes: 1 addition & 1 deletion libxml++/nodes/entityreference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <libxml++/nodes/entityreference.h>

#include <libxml/tree.h>
#include <libxml/entities.h>

namespace xmlpp
{
Expand Down
1 change: 1 addition & 0 deletions libxml++/validators/relaxngvalidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "libxml++/parsers/domparser.h"
#include "libxml++/relaxngschema.h"

#include <libxml/tree.h>
#include <libxml/relaxng.h>

namespace xmlpp
Expand Down
10 changes: 9 additions & 1 deletion tests/saxparser_chunk_parsing_inconsistent_state/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@

class MySaxParser : public xmlpp::SaxParser
{
public:
bool throw_on_start_doc = true;

protected:
void on_start_document() override
{
throw std::runtime_error("some custom runtime exception");
if (throw_on_start_doc)
throw std::runtime_error("some custom runtime exception");
}
void on_error(const xmlpp::ustring& /* text */) override
{
Expand All @@ -43,6 +47,9 @@ int main()
bool exceptionThrown = false;
try
{
// Depending on the libxml2 version, MySaxParser::on_start_document()
// may or may not be called before MySaxParser::on_error().
parser.throw_on_start_doc = false;
parser.parse_chunk("<?");
parser.finish_chunk_parsing();
}
Expand All @@ -61,6 +68,7 @@ int main()
exceptionThrown = false;
try
{
parser.throw_on_start_doc = true;
std::stringstream ss("<root></root>");
parser.parse_stream(ss);
}
Expand Down

0 comments on commit 4947181

Please sign in to comment.