[lxml-dev] Bug in XPath evaluation - not a bug :)

Stefan Behnel stefan_ml at behnel.de
Mon Apr 23 18:09:36 CEST 2007


Hi,

Torsten Rehn wrote:
> On Mon, 2007-04-23 at 08:24 +0200, Stefan Behnel wrote:
>> You should pass the namespace-prefix mapping to lxml. See the docs on this topic:
>>
>> http://codespeak.net/lxml/dev/xpathxslt.html#xpath
> 
> Ah, looking at the development version's page obviously helps ;)

Actually it's reading the documentation which helps:
http://codespeak.net/lxml/api.html#xpath

It's been in there for at least a year.


>>> etree.XPathSyntaxError: error in xpath expression
>> As expected. Undefined prefixes are invalid.
> 
> But it is valid XPath 1.0, isn't it? I'm just a little confused by the
> term "XPath Syntax Error". As far as I understand the issue, the problem
> is not with the syntax but with lxml (or whatever lies beneath) not
> supporting some of it (which is ok with the W3C recommendation).
> I'm making that much of a problem out of it because my app processes XML
> documents that use namespaces quite extensively. And these namespaces
> may be different for every XML doc that comes along, so I would have to
> scan the file for xmlns attributes first (and then call the .xpath()
> method with the second argument as described on the page you posted),

So you're really ignoring the namespace and just looking at the prefix? That's
definitely an unusual use case.

What's the use in accepting any namespace in an XPath expression as long as
the prefix is the same? I mean, honestly, the prefix doesn't tell you
anything, right?

Stefan



More information about the lxml-dev mailing list