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.

Author mbakeranalecta
Recipients docs@python, mbakeranalecta
Date 2015-02-09.19:39:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1423510779.4.0.551912157105.issue23423@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-02-09 19:39:39mbakeranalectasetrecipients: + mbakeranalecta, docs@python
2015-02-09 19:39:39mbakeranalectasetmessageid: <1423510779.4.0.551912157105.issue23423@psf.upfronthosting.co.za>
2015-02-09 19:39:39mbakeranalectalinkissue23423 messages
2015-02-09 19:39:38mbakeranalectacreate