[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [xml] XPath evaluation and namespace prefixes
- From: Daniel Veillard <veillard redhat com>
- To: "John L. Clark" <jclark nps navy mil>
- Cc: xml gnome org
- Subject: Re: [xml] XPath evaluation and namespace prefixes
- Date: Thu, 4 Mar 2004 16:31:39 -0500
On Thu, Mar 04, 2004 at 12:22:00PM -0800, John L. Clark wrote:
> I am trying to evaluate an XPath expression that involves namespace
> prefixes. Just trying to use node.xpathEval('//pre:element') fails
> with:
>
> 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
in scope of what ??? no there is no definition for this...
> XPath evaluation context to specify my namespace prefix bindings.
yes.
> 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.
The ultimate is the XPath REC
http://www.w3.org/TR/xpath
Introduction:
"Expression evaluation occurs with respect to a context. XSLT and XPointer specify how the context is determined for XPath expressions used in XSLT and XPointer respectively. The context consists of:
* a node (the context node)
* a pair of non-zero positive integers (the context position and the context size)
* a set of variable bindings
* a function library
* the set of namespace declarations in scope for the expression
"
Which clearly means "it's not XPath business to initialize that context"
> 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
Might be a bug in Python bindings.
> The same thing happens when I try to use setContextNode (with a node
> instead of doc). I am ...
Setting the node and the document for the context node is anyway
independant of setting the namespace declarations in scope for the expression
> Can someone point me in the right direction?
In any doubt readingt the spec first helps disambiguating.
> Is this latter problem a bug?
Probably.
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]