Re: [xml-bindings] XPointer & string-range with libxml2-python

On Mon, May 02, 2005 at 01:38:55PM +0200, Hanh-Missi Tran wrote:
> Hi
> I want to evaluate XPointer expressions with libxml2-python. It works 
> well when a XPointer selects one or several nodes. However I do not 
> succeed in evaluating XPointer that uses the function string-range.
> For example, here is my xml file:
> <?xml version = "1.0"?>
>        <ENTRY ID="pa">
>                <NAME>Pieter</NAME>
>        </ENTRY>
>        <ENTRY ID="en">
>                <NAME>Emeka</NAME>
>        </ENTRY>
> And here is my code:
> import libxml2
> doc=libxml2.parseFile("addrbook.xml")
> root=doc.children
> ctx=root.xpointerNewContext(doc,None)
> ctx.xpointerEval('xpointer(string-range(ADDRBOOK/ENTRY[1]/NAME[1],"Pieter"))')
> It does not work and it gives me the following error:
> Unable to convert XPath object type 7

  it's an XPath XPATH_LOCATIONSET value, the python wrappers don't know how
to handle it. it is a limitation of the current python bindings.

> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "/usr/lib/python2.3/site-packages/", line 6443, in 
> xpointerEval
>    if ret is None:raise treeError('xmlXPtrEval() failed')
> libxml2.treeError: xmlXPtrEval() failed
> Is there something wrong in my code or in my XPointer ? Does the 

  a priori no

> evaluation of that XPointer work if I use libxml2 directly ?

  it's likely.

> Moreover several xpointer-functions of xmlNode 
> (xpointerNewCollapsedRange ...) do not work.
> I have tried with an old version (python2.3.4 and libxml2-2.6.13) and 
> with the latest(python2.4.1 and libxml2-2.6.19) but there have not been 
> any improvements.

  right. There haven't been much interest in range selections of XPointer,
so the code might be a bit incomplete. The python bindings definitely are
incomplete in this respect.


Daniel Veillard      | Red Hat Desktop team
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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