[libxml2] Deprecate old HTML SAX API



commit a308c0cdf74de1ee446c2bab1ff752f554b8669d
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Thu Aug 25 20:18:16 2022 +0200

    Deprecate old HTML SAX API

 HTMLparser.c                |  4 ++++
 include/libxml/HTMLparser.h |  2 ++
 python/libxml.c             |  5 ++++-
 runtest.c                   | 12 ++++++++++--
 4 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/HTMLparser.c b/HTMLparser.c
index f8ff2d2a..eae6524f 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -6402,6 +6402,8 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
  * @sax:  the SAX handler block
  * @userData: if using SAX, this pointer will be provided on callbacks.
  *
+ * DEPRECATED: Use htmlNewSAXParserCtxt and htmlCtxtReadDoc.
+ *
  * Parse an HTML in-memory document. If sax is not NULL, use the SAX callbacks
  * to handle parse events. If sax is NULL, fallback to the default DOM
  * behavior and return a tree.
@@ -6523,6 +6525,8 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
  * @sax:  the SAX handler block
  * @userData: if using SAX, this pointer will be provided on callbacks.
  *
+ * DEPRECATED: Use htmlNewSAXParserCtxt and htmlCtxtReadFile.
+ *
  * parse an HTML file and build a tree. Automatic support for ZLIB/Compress
  * compressed document is provided by default if found at compile-time.
  * It use the given SAX function block to handle the parsing callback.
diff --git a/include/libxml/HTMLparser.h b/include/libxml/HTMLparser.h
index 93d7fb4a..78f04d8d 100644
--- a/include/libxml/HTMLparser.h
+++ b/include/libxml/HTMLparser.h
@@ -120,6 +120,7 @@ XMLPUBFUN htmlParserCtxtPtr XMLCALL
 
 XMLPUBFUN int XMLCALL
                        htmlParseDocument(htmlParserCtxtPtr ctxt);
+XML_DEPRECATED
 XMLPUBFUN htmlDocPtr XMLCALL
                        htmlSAXParseDoc (const xmlChar *cur,
                                         const char *encoding,
@@ -131,6 +132,7 @@ XMLPUBFUN htmlDocPtr XMLCALL
 XMLPUBFUN htmlParserCtxtPtr XMLCALL
                        htmlCreateFileParserCtxt(const char *filename,
                                                 const char *encoding);
+XML_DEPRECATED
 XMLPUBFUN htmlDocPtr XMLCALL
                        htmlSAXParseFile(const char *filename,
                                         const char *encoding,
diff --git a/python/libxml.c b/python/libxml.c
index ead223f1..9c442a33 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -1557,6 +1557,7 @@ libxml_htmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
     const char *encoding;
     PyObject *pyobj_SAX = NULL;
     xmlSAXHandlerPtr SAX = NULL;
+    htmlParserCtxtPtr ctxt;
 
     if (!PyArg_ParseTuple
         (args, (char *) "Osz:htmlSAXParseFile", &pyobj_SAX, &URI,
@@ -1574,7 +1575,9 @@ libxml_htmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
     SAX = &pythonSaxHandler;
     Py_INCREF(pyobj_SAX);
     /* The reference is released in pythonEndDocument() */
-    htmlSAXParseFile(URI, encoding, SAX, pyobj_SAX);
+    ctxt = htmlNewSAXParserCtxt(SAX, pyobj_SAX);
+    htmlCtxtReadFile(ctxt, URI, encoding, 0);
+    htmlFreeParserCtxt(ctxt);
     Py_INCREF(Py_None);
     return (Py_None);
 #else
diff --git a/runtest.c b/runtest.c
index 8626b91f..0b07c543 100644
--- a/runtest.c
+++ b/runtest.c
@@ -1726,7 +1726,11 @@ saxParseTest(const char *filename, const char *result,
 
 #ifdef LIBXML_HTML_ENABLED
     if (options & XML_PARSE_HTML) {
-       htmlSAXParseFile(filename, NULL, emptySAXHandler, NULL);
+        htmlParserCtxtPtr ctxt;
+
+        ctxt = htmlNewSAXParserCtxt(emptySAXHandler, NULL);
+        htmlCtxtReadFile(ctxt, filename, NULL, options);
+        htmlFreeParserCtxt(ctxt);
        ret = 0;
     } else
 #endif
@@ -1750,7 +1754,11 @@ saxParseTest(const char *filename, const char *result,
     }
 #ifdef LIBXML_HTML_ENABLED
     if (options & XML_PARSE_HTML) {
-       htmlSAXParseFile(filename, NULL, debugHTMLSAXHandler, NULL);
+        htmlParserCtxtPtr ctxt;
+
+        ctxt = htmlNewSAXParserCtxt(debugHTMLSAXHandler, NULL);
+        htmlCtxtReadFile(ctxt, filename, NULL, options);
+        htmlFreeParserCtxt(ctxt);
        ret = 0;
     } else
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]