Closed sdkeens closed 1 month ago
Note that I have also tested the XML file and the XPath with the online XPath tester: https://www.freeformatter.com/xpath-tester.html It returns the expected value.
I forgot to mention:
Hi, the point is the same that i described in my last comment here: https://github.com/sissaschool/elementpath/issues/72#issuecomment-2375146627.
So it was a bug in v4.4 that erroneously usse the namespaces of the instance (an lxml's tree ...) to resolve the prefixes of the XPath expression. Also in this case with the default namespace. XPath explicitly states that the namespaces map must be provided to the static context. If not the empty prefix must be mapped to no namespace.
I could left this automatism for lxml but, apart the consideration on different results comparing to ElementTree, the fact is that also lxml doesn't consider the instance namespaces for parsing the path when one use the xpath()
API. For proving that you have to try apply xml_et_root.xpath(xpath)
, that returns the empty list.
So the solution is to provide a mapping for the empty namespace:
namespaces = {'': "http://www.pcigeomatics.com/xmlschema/gdbmetadata/1.0.0"}
xpath = '/GDBFile/Imagery/Channels/Channel[@id=1]/DataType'
xpath_result = elementpath.select(xml_et_root, xpath,
parser=XPath3Parser,
namespaces=namespaces,
default_collation=elementpath.collations.UNICODE_CODEPOINT_COLLATION)
Best regards
Hi Brunato,
Thanks for the information. I will close this issue.
I have found an XPath that succeeds with
elementpath
version 4.1.5 and fails with version 4.5.The pyunit.zip file contains a python unit test and an XML file that I used to test the two versions of
elementpath
.pyunit.zip
For you information, here's the list of packages I have installed: