I have an XML <root> element with several attributes. I've been using the ElementTree package.
After I've parsed a tree from an xml file, I'm getting the document root, but I want to get the requested attribute, or even the entire list of attributes.
<root a="1" b="2" c="3">
</blablabla>
</root>
How can I retrieve all attribute names and values for a <root> element with ElementTree?
Each
Elementhas an attribute.attribthat is a dictionary; simply use it's mapping methods to ask it for it's keys or values:or
or use
.values()or any of the other methods available on a pythondict.To get an individual attribute, use the standard subscription syntax: