Last active
March 3, 2017 12:38
-
-
Save cipri-tom/f85b246fc8a250ea4debf9178a2732b9 to your computer and use it in GitHub Desktop.
etree bug function namespace prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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