diff --git a/ext/nokogiri/html_sax_parser_context.c b/ext/nokogiri/html_sax_parser_context.c
index 9f41b51adf..7f1379abf2 100644
--- a/ext/nokogiri/html_sax_parser_context.c
+++ b/ext/nokogiri/html_sax_parser_context.c
@@ -92,6 +92,8 @@ parse_with(VALUE self, VALUE sax_handler)
ctxt->sax = sax;
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
+ xmlSetStructuredErrorFunc(NULL, NULL);
+
rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);
return self;
diff --git a/ext/nokogiri/html_sax_push_parser.c b/ext/nokogiri/html_sax_push_parser.c
index 2df4532f10..3a739ae1d2 100644
--- a/ext/nokogiri/html_sax_push_parser.c
+++ b/ext/nokogiri/html_sax_push_parser.c
@@ -20,6 +20,8 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
size = (int)RSTRING_LEN(_chunk);
}
+ xmlSetStructuredErrorFunc(NULL, NULL);
+
if(htmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
if (!(ctx->options & XML_PARSE_RECOVER)) {
xmlErrorPtr e = xmlCtxtGetLastError(ctx);
diff --git a/ext/nokogiri/xml_sax_parser_context.c b/ext/nokogiri/xml_sax_parser_context.c
index 19c96c69c1..370d7b9fc3 100644
--- a/ext/nokogiri/xml_sax_parser_context.c
+++ b/ext/nokogiri/xml_sax_parser_context.c
@@ -120,6 +120,8 @@ parse_with(VALUE self, VALUE sax_handler)
ctxt->sax = sax;
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
+ xmlSetStructuredErrorFunc(NULL, NULL);
+
rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);
return Qnil;
diff --git a/ext/nokogiri/xml_sax_push_parser.c b/ext/nokogiri/xml_sax_push_parser.c
index dac0a24db5..9daa22767d 100644
--- a/ext/nokogiri/xml_sax_push_parser.c
+++ b/ext/nokogiri/xml_sax_push_parser.c
@@ -35,6 +35,8 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
size = (int)RSTRING_LEN(_chunk);
}
+ xmlSetStructuredErrorFunc(NULL, NULL);
+
if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
if (!(ctx->options & XML_PARSE_RECOVER)) {
xmlErrorPtr e = xmlCtxtGetLastError(ctx);