The official documentation here just says, “match may be a tag name or path”, but I don’t see a definition of “path” anywhere. From looking at examples on the web I gather it’s some stripped-down XPath-like notation, but it’s unclear exactly what is allowed — for example, should the path start with a /, a //, or no delimiter at all? Can I specify attributes with [@att = "value"]?
The official documentation here just says, match may be a tag name or path,
Share
Well, looking at the source code at http://hg.python.org/cpython/file/2.7/Lib/xml/etree/ElementTree.py we find that
Element.findis implemented asElementPathis implemented as_SimpleElementPathonly checks tag name:So let’s look at ElementPath.py: http://hg.python.org/cpython/file/f98e2944cb40/Lib/xml/etree/ElementPath.py It states,
So I would assume valid XPath is likely a valid argument for
find. I’m not familiar enough with XPath to determine exactly what it supports, but http://effbot.org/zone/element-xpath.htm describes how much it supported five years ago and includes a table of syntax.http://docs.python.org/dev/library/xml.etree.elementtree.html#xpath-support has a more updated table. It doesn’t look too different.