Re: [xml-bindings]Python bindings suggestions
- From: Daniel Veillard <veillard redhat com>
- To: Gary Benson <gary inauspicious org>
- Cc: xml-bindings gnome org
- Subject: Re: [xml-bindings]Python bindings suggestions
- Date: Tue, 5 Mar 2002 13:24:06 -0500
On Mon, Mar 04, 2002 at 07:01:18PM -0500, Daniel Veillard wrote:
> On Mon, Mar 04, 2002 at 10:05:03PM +0000, Gary Benson wrote:
> > This would probably be more easily done in the Python part:
> >
> > ret = _libxml.xmlNewTextChild(self._o, ns__o, name, content)
> > if ret == None: raise error("xmlNewTextChild() failed")
>
> well I would have to define an treeError class and raise this, in this
> case. I agree this would simplify programming with the bindings a lot,
> => TODO
Done libxml2 wrapper can now raise treeError, parserError, uriError or
xpathError on functions or methods returning one of the libxml2 classes
and the return value being None.
> > My second suggestion is this: in quite a lot of Python modules where is
> > something that requires a callback there will be an example one filled
> > with empty functions. For the SAX parser, for example, something like
> > (only a couple of methods shown):
> >
> > class SAXCallback:
[...]
> But I agree a full exemple should be provided at least.
Done it describes all the SAX entry points, but doesn't show up
the xmllib compatibility callbacks which are accepted too.
> > 1. The only SAX parser creator seems to be a memory parser -- is there a
> > way of creating one that will parse a file instead? I'm currently
> > using something like:
>
> Hum, I would need a wrapper for something like
> xmlDocPtr xmlSAXParseFile (xmlSAXHandlerPtr sax,
> const char *filename,
> int recovery);
>
> > It's not a problem, but it seems like something I should be able to do
> > with the library.
>
> agreed,
Done:
def SAXParseFile(SAX, URI, recover):
"""Interface to parse an XML file or resource pointed by an
URI to build an event flow to the SAX object"""
libxml2mod.xmlSAXParseFile(SAX, URI, recover)
and
def htmlSAXParseFile(SAX, URI, encoding):
"""Interface to parse an HTML file or resource pointed by an
URI to build an event flow to the SAX object"""
libxml2mod.htmlSAXParseFile(SAX, URI, encoding)
but untested.
> > 3. How do you evaluate an XPath expression with a relative path? For
> > instance, if the above example had worked and nodes[0] was an xmlNode,
> > how would I select into it? I'd _expect_ to do something like:
> >
> > film_node = nodes[0]
> > photo = "12"
> > ctxt2 = film_node.xpathNewContext()
> > nodes2 = ctxt2.xpathEval(photo[ num=%s]" % photo)
> >
> > But of course that doesn't work ;-)
>
> The context should really be created against the document, but
> an accessor should be added to allow setting the current node, this is
> lacking ATM, it's just an entry needed in libxml2-python-api.xml to
> provided it.
Done:
tests/xpath.py
-------------
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//*")
...
ctxt.setContextNode(res[0])
res = ctxt.xpathEval("foo")
-------------
this has been commited in CVS:
http://cvs.gnome.org/bonsai/cvsquery.cgi?module=gnome-xml&branch=HEAD&branchtype=match&dir=gnome-xml&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=03%2F05%2F02+10%3A40&maxdate=03%2F05%2F02+10%3A42&cvsroot=%2Fcvs%2Fgnome
thanks for the feedback,
Daniel
--
Daniel Veillard | Red Hat Network https://rhn.redhat.com/
veillard redhat com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]