Re: [xml] How to reset an HTML push parser context?

Daniel Veillard wrote:
On Tue, Sep 11, 2007 at 01:26:30PM +0200, Stefan Behnel wrote:
cdef int _htmlCtxtResetPush(xmlparser.xmlParserCtxt* c_ctxt,
                            char* c_data, int buffer_len,
                            char* c_encoding, int parse_options) except -1:
    # libxml2 crashes if spaceTab is not initialised
    if _LIBXML_VERSION_INT < 20629 and c_ctxt.spaceTab is NULL:
        c_ctxt.spaceTab = <int*>tree.xmlMalloc(10 * sizeof(int))
        if c_ctxt.spaceTab is NULL:
        c_ctxt.spaceMax = 10

  xmlCtxtResetPush should instead be fixed to cope with that condition.

Mind the "if _LIBXML_VERSION_INT < 20629" :)

    # libxml2 lacks an HTML push parser setup function
    error = xmlparser.xmlCtxtResetPush(c_ctxt, NULL, 0, NULL, c_encoding)
    if error:
        return error

    # fix libxml2 setup for HTML = 1
    c_ctxt.html = 1
    htmlparser.htmlCtxtUseOptions(c_ctxt, parse_options)

    if c_data is not NULL and buffer_len > 0:
        return htmlparser.htmlParseChunk(c_ctxt, c_data, buffer_len, 0)

  If you think a real C function htmlCtxtResetPush might be useful, then
as usual I take patches ! :-)

Hmmm, I might not use an official function myself, as lxml currently wants to
stay backwards compatible with libxml2 2.6.20, but I'll see what I can come up


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