Stefan Behnel <stefan...@behnel.de> added the comment:

lxml has a couple of nice features here:

- all tags in a namespace: "{namespace}*"
- a local name 'tag' in any (or no) namespace: "{*}tag"
- a tag without namespace: "{}tag"
- all tags without namespace: "{}*"

"{*}*" is also accepted but is the same as "*". Note that "*" is actually 
allowed as an XML tag name by the spec, but rare enough to hijack it for this 
purpose. I've actually never seen it used anywhere in the wild.

lxml's implementation isn't applicable to ElementTree (searching has been 
subject to excessive optimisation), but it shouldn't be hard to extend the one 
in ET's ElementPath.py module, as well as Element.iter() in ElementTree.py, to 
support this kind of tag comparison.

PR welcome.

lxml's tests are here (and in the following test methods):

https://github.com/lxml/lxml/blob/359f693b972c2e6b0d83d26a329d2d20b7581c48/src/lxml/tests/test_etree.py#L2911

Note that they actually test the deprecated .getiterator() method for 
historical reasons. They should probably call .iter() instead these days. 
lxml's ElementPath implementation is under src/lxml/_elementpath.py, but the 
tag comparison itself is done elsewhere in Cython code (here, in case it 
matters:)

https://github.com/lxml/lxml/blob/359f693b972c2e6b0d83d26a329d2d20b7581c48/src/lxml/apihelpers.pxi#L921-L1048

----------
stage:  -> needs patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue28238>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to