Next / Previous / Contents / Shipman's homepage

9.13. Element.items(): Produce attribute names and values

For any Element instance E, the .items() method returns the attributes as if they were a dictionary and you had called the .items() method on that dictionary: the result is a list of two-element tuples (name, value), one for each XML attribute of E.

Attribute values are returned in no particular order.

Here's an example.

>>> node = etree.fromstring("<event time='1830' cost='3.50' rating='nc-03'/>")
>>> node.items()
[('cost', '3.50'), ('time', '1830'), ('rating', 'nc-03')]
>>>