-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ElementPath #75829
Comments
Both currently raise "invalid path" exceptions. PR coming. |
Is this feature already implemented in lxml? Is it a part of some wider standard? |
Well, there's XPath for a standard: ElementPath deviates from it in its namespace syntax (it allows "{ns}tag" where XPath requires "p:tag" prefixes), but that's about it. All other differences are basically needless limitations of ElementPath. In fact, I had noticed these two limitations in lxml, so I implemented them for the next release. And since ElementPath in ElementTree is still mostly the same as ElementPath in lxml, here's the same thing for ET. |
I think the break in the loop for [.='text'] is not correct. >>> from xml.etree import ElementTree as ET
>>> e = ET.XML('<root><a><b>text</b></a><a><b></b></a><a><b>text</b></a></root>')
>>> list(e.findall('.//a[b="text"]'))
[<Element 'a' at 0x7ffadb305d58>, <Element 'a' at 0x7ffadb305f58>]
>>> list(e.findall('.//a[.="text"]'))
[<Element 'a' at 0x7ffadb305d58>] I expect that findall() finds all matched elements, not just the first one. Both above requests should return the same result. |
Thanks for noticing. I added a test and fixed it. |
Thank you for your contribution Stefan! Good improvement. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: