Some string comparisson does not work inside an xpath expression
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Invalid
|
Undecided
|
Unassigned |
Bug Description
When trying to compare two strings with an operator different than "=" the xpath does not evaluate properly, giving 0 results for structures which contain nodes that would be valid for the comparison expression. For example:
Given the following content of an xml
<nodes>
<a>test</a>
<b>test1</b>
</nodes>
and the following python code (attached for better access):
# Import python utilities
import argparse
# Import xml parser
from lxml import etree
if __name__ == "__main__":
xml = etree.XML(
xpath_xml = etree.XPathEval
# Testing = operator
test = xpath_xml(
assert len(test) == 1
# Testing = operator
test = xpath_xml(
assert len(test) == 1
# Testing > operator
test = xpath_xml(
assert len(test) == 1
The python code fails to get the b node when the comparison is ">".
Is this a bug? or it is just not supported?
Note that the xpath evaluator does not raise any error.
Here the information requested for the investigation:
$ python3 lxml_info.py
Python : sys.version_
lxml.etree : (3, 3, 3, 0)
libxml used : (2, 9, 1)
libxml compiled : (2, 9, 1)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)
Thanks for you support.
Best regards.
XPath 1.0 does not support this. A PR for implementing this in ElementPath (perferably both in CPython and lxml) would be welcome.
"When neither object to be compared is a node-set and the operator is <=, <, >= or >, then the objects are compared by converting both objects to numbers and comparing the numbers according to IEEE 754. The < comparison will be true if and only if the first number is less than the second number. The <= comparison will be true if and only if the first number is less than or equal to the second number. The > comparison will be true if and only if the first number is greater than the second number. The >= comparison will be true if and only if the first number is greater than or equal to the second number."
https:/ /www.w3. org/TR/ 1999/REC- xpath-19991116/ #booleans