Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:
Installation Installation:
pip install untangle
Usage Usage:
Your xmlXML file (a little bit changed):
<foo>
<bar name="bar_name">
<type foobar="1"/>
</bar>
</foo>
accessingAccessing the attributes with untangleuntangle:
import untangle
obj = untangle.parse('/path_to_xml_file/file.xml')
print obj.foo.bar['name']
print obj.foo.bar.type['foobar']
theThe output will be:
bar_name
1
More information about untangle can be found in "hereuntangle".
Also (if
Also, if you are curious), you can find a list of tools for working with XML and Python in "herePython and XML (you". You will also see that the most common ones were mentioned by previous answers).