[xml] help! python wrapper for the xslt loader API



I've knocked up a patch for python wrapping the xslt loader API. 

My patch facilitates writing loaders in python.

But I'm having problems getting the xmlDocPtr back from a python
function.

The task is more complex than it would first appear because it is
necessary to have python use the current parserContext so the intern
dictionaries can be retained. 

The trouble is the parserContext functions handling context attached
parsing clear the document from the parserContext after they've parsed
it. So the python has to _return_ the doc.


I've got code like this:

        ctxtobj = libxml_xmlParserCtxtPtrWrap(pctxt);
        result = PyObject_CallFunction(pythonDocLoaderObject, 
                                       (char *) "(sO)", URI, ctxtobj);
        Py_XDECREF(ctxtobj);

        // The return value should be the document
        // 
        // libxml2/parser.c::xmlDoRead sets the parserContext's doc member to NULL
        // otherwise we could simply use that.
        if (result != NULL) {
            doc = PyxmlNode_Get(result);
        }


When I do this I don't seem to get a valid doc.

The python I'm using is:

 def fn(url, ctx):
    try:
        # print url
        ctxt = libxml2.parserCtxt(_obj=ctx)
        doc = ctxt.ctxtReadDoc("""<?xml version='1.0'?><b/>""", url, "UTF-8", 0)
        return doc
    except Exception, e:
        print >>sys.stderr, "something went wrong:", e
        return None

The return value of ctxtReadDoc is a PyCObject wrapped xmlDocPtr so I
presumed that I'd just be able to access it with PyxmlNode_Get. But as
I say... this is not so.


Anybody know what mantra I need to get at the doc object returned from
python in this instance?

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   for all your tapsell ferrier needs



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