[xml] XPath evaluation and namespace prefixes

I am trying to evaluate an XPath expression that involves namespace
prefixes.  Just trying to use node.xpathEval('//pre:element') fails

    Undefined namespace prefix
    xmlXPathEval: evaluation failed
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File "/usr/lib/python2.3/site-packages/libxml2.py", line 361, in xpathEval
        res = ctxt.xpathEval(expr)
      File "/usr/lib/python2.3/site-packages/libxml2.py", line 6221, in xpathEval
        if ret is None:raise xpathError('xmlXPathEval() failed')
    libxml2.xpathError: xmlXPathEval() failed

And so I assumed that perhaps the XPath evaluation engine does not pick
up on namespaces that are in scope, and that I would have to craft an
XPath evaluation context to specify my namespace prefix bindings.

    Note: I don't know if my assumptions are correct; it is hard to find
          precise documentation on the semantics of the various API
          points of entry, and even harder when it comes to the Python
          API.  As such, corrections of any of my erroneous
          assumptions/approaches are welcome.

So I get started on experimenting with the xpathContext class in Python
from the command line:

    Python 2.3.2 (#1, Nov 21 2003, 14:36:46)
    [GCC 3.3.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import libxml2
    >>> doc = libxml2.parseFile('overview.xml.rdf')
    >>> xc = libxml2.xpathContext()
    >>> xc
    <libxml2.xpathContext instance at 0x40a4f30c>
    >>> xc.setContextDoc(doc)
    Segmentation fault 

The same thing happens when I try to use setContextNode (with a node
instead of doc).  I am ...

    Using libxml 20606, libxslt 10103 and libexslt 803
    xsltproc was compiled against libxml 20606, libxslt 10103 and libexslt 803
    libxslt 10103 was compiled against libxml 20606
    libexslt 803 was compiled against libxml 20606

Can someone point me in the right direction?  Is this latter problem a

Take care,

    John L. Clark

Attachment: pgpPZYvLnVFHz.pgp
Description: PGP signature

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