![](https://secure.gravatar.com/avatar/51040b16bc3fe1e094f14bd3a2d52aec.jpg?s=120&d=mm&r=g)
I'm maintaining older code, which just broke because lxml took out xpath.evaluate(). The only note in the lxml changelog about it says it was 'redundant', meaning (I assume) that there's a better way to do the same thing, but there's no documentation about what that other way might be. Does anyone know what the new code should be? The code in question looks like: xpath = lxml.etree.XPath(target, namespaces=namespaces) root = lxml.etree.Element("root") try: xpath.evaluate(root) if model_etree and check_in_model_source: [etc. etc.] except lxml.etree.XPathEvalError as exception: if 'Undefined namespace prefix' in str(exception):
![](https://secure.gravatar.com/avatar/bad73a18a6cce33fce0ebd868981313b.jpg?s=120&d=mm&r=g)
The XPath object is callable, simply treat it as a function. On 2/16/24 00:38, lpsmith@uw.edu wrote:
I'm maintaining older code, which just broke because lxml took out xpath.evaluate(). The only note in the lxml changelog about it says it was 'redundant', meaning (I assume) that there's a better way to do the same thing, but there's no documentation about what that other way might be.
Does anyone know what the new code should be? The code in question looks like:
xpath = lxml.etree.XPath(target, namespaces=namespaces) root = lxml.etree.Element("root") try: xpath.evaluate(root)
if model_etree and check_in_model_source:
[etc. etc.]
except lxml.etree.XPathEvalError as exception: if 'Undefined namespace prefix' in str(exception): _______________________________________________ lxml - The Python XML Toolkit mailing list -- lxml@python.org To unsubscribe send an email to lxml-leave@python.org https://mail.python.org/mailman3/lists/lxml.python.org/ Member address: xmo@odoo.com
![](https://secure.gravatar.com/avatar/8b97b5aad24c30e4a1357b38cc39aeaa.jpg?s=120&d=mm&r=g)
lpsmith@uw.edu schrieb am 16.02.24 um 00:38:
I'm maintaining older code, which just broke because lxml took out xpath.evaluate(). The only note in the lxml changelog about it says it was 'redundant', meaning (I assume) that there's a better way to do the same thing, but there's no documentation about what that other way might be.
Does anyone know what the new code should be? The code in question looks like:
xpath = lxml.etree.XPath(target, namespaces=namespaces) root = lxml.etree.Element("root") try: xpath.evaluate(root)
You can simply call the XPath object. Thus, it's common to write something like find_config = lxml.etree.XPath("//config[1]") config_element = find_config(root) https://lxml.de/xpathxslt.html#the-xpath-class Stefan
participants (3)
-
lpsmith@uw.edu
-
Stefan Behnel
-
Xavier Morel