Skip to content

Instantly share code, notes, and snippets.

@cipri-tom
Last active March 3, 2017 12:38
Show Gist options
  • Save cipri-tom/f85b246fc8a250ea4debf9178a2732b9 to your computer and use it in GitHub Desktop.
Save cipri-tom/f85b246fc8a250ea4debf9178a2732b9 to your computer and use it in GitHub Desktop.
etree bug function namespace prefix
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from lxml import etree
etree.FunctionNamespace("http://exslt.org/regular-expressions").prefix = 're'
text = """
<monthEntity month="02" year="1998">
<article>
<full_text> Some article text </full_text>
<full_text> Some more article text fragment 2 </full_text>
</article>
</monthEntity>
"""
t = etree.fromstring(text)
search = etree.XPath('//full_text[re:match(text(), "fragment")]')
search(t) # this one works. returns a list with 1 element
search(t) # this one fails with
# src/lxml/xpath.pxi in lxml.etree.XPath.__call__ (src/lxml/lxml.etree.c:172853)()
# ...
# XPathFunctionError: XPath function '{�{|}match' not found
# The thing before `match` in curly braces sometimes changes on different runs of the program
# So this could be a bug somewhere
# using etree.__version__ 3.7.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment