[lxml-dev] Bug in XPath evaluation - not a bug :)
Torsten Rehn
scel at users.sourceforge.net
Mon Apr 23 17:54:34 CEST 2007
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 ;)
> > 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),
which is kind of ugly in my opinion. In my specific scenario it is a lot
harder to get the namespace URI than to get the namespace prefix.
Is there a good reason I am overlooking or why can I use name() in a
predicate to find my node without the URI, but cannot use the better
looking abbreviated syntax without an explicit predicate?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: This is a digitally signed message part
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20070423/1356625c/attachment.pgp
More information about the lxml-dev
mailing list