Re: [xml-bindings]Python bindings suggestions



On Mon, 4 Mar 2002, Daniel Veillard wrote:

> On Mon, Mar 04, 2002 at 10:05:03PM +0000, Gary Benson wrote:
> 
> > That way you get something like "libxml2.error: xmlNewTextChild()
> > failed"  in the backtrace, and you can "except libxml2.error" to catch
> > problems if you want. Hopefully this won't be too hard to implement
> > since I understand that libxml2.py is automatically generated anyway.
> 
> Yep for the most part, basically I would raise this for all methods
> returning xmlCore (or subclasses of it). Should that be systematic, i.e.
> any function or method expecting to return a class should raise
> exception if the return is None ?

Hmmm, I'd probably have to say no here. Probably the best thing to do 
would be to raise exceptions for errors (no ram, document not well formed, 
etc) and return an empty version of what you were expecting otherwise.
For instance, xmlNode.prop() should return an empty string if the property 
is not present. Maybe.

I expect you could debate this till the cows come home ;)

> > 2. I tried using the following bit of XPath but it didn't return any nodes 
> >    (it should have returned one). Have I done something stupid, or is it 
> >    a bug?
> > 
> >     film = "022"
> >     doc = libxml2.parseFile(path)
> >     ctxt = doc.xpathNewContext()
> >     nodes = ctxt.xpathEval("/photodb/film[ num=%s]" % film)
> 
>    "/photodb/film[ num=%s]" % film
>    would give 
>    "/photodb/film[ num=022]"
>    and that may not work well, possibly
>    "/photodb/film[ num='%s']" % film
>    would give better results

Ahhh. I've only used XPath in the context of XSL, and I think quotes get 
hidden from you there. That explains it, thanks :)

> There is definitely a bit of polishing needed, thanks for the
> suggestions I will try to implement them before the next release.

Suggesting is easier than coding -- keep up the good work!

Cheers,
Gary

[ gary inauspicious org ][ GnuPG 85A8F78B ][ http://inauspicious.org/ ]




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