This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: XPath Support in ElementTree doc omission
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, mbakeranalecta, scoder
Priority: normal Keywords:

Created on 2015-02-09 19:39 by mbakeranalecta, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg235627 - (view) Author: Mark Baker (mbakeranalecta) Date: 2015-02-09 19:39
The list of XPath supported features in section 20.5.2.2. "Supported XPath syntax" on page https://docs.python.org/3.4/library/xml.etree.elementtree.html does not list the use of a predicate based on an element value (it only list predicates based on an attribute value. However, testing in 3.4 shows that a predicate based on an element value also works.

>>> import xml.etree.ElementTree as etree
>>> x = '<foo><bar><baz y="bang">bing</baz></bar></foo>'
>>> y = etree.XML(x)

# Find by attribute value
>>> z = y.find('bar/baz[@y="bang"]')
>>> print(z)
<Element 'baz' at 0x0000000003300368>

# Find by element value
>>> z = y.find('bar/[baz="bing"]')
>>> print(z)
<Element 'bar' at 0x000000000334AD18>

# Find fails with incorrect element value
>>> z = y.find('bar/[baz="bong"]')
>>> z
>>> print(z)
None


Below the line that says:

[tag]	Selects all elements that have a child named tag. Only immediate children are supported.

It should say something like:

[tag="value"]	Selects all elements that have a child named tag with the given value. Only immediate children are supported.
msg350436 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2019-08-25 07:45
Already fixed in later versions of the documentation:
https://docs.python.org/3/library/xml.etree.elementtree.html#supported-xpath-syntax

Note that Py3.4 is no longer maintained.
History
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67611
2019-08-25 07:45:59scodersetstatus: open -> closed
resolution: out of date
messages: + msg350436

stage: resolved
2019-08-25 07:00:53xtreaksetnosy: + scoder
2015-02-09 19:39:39mbakeranalectacreate