Reputation: 257
I am trying to read some xml, but I'm not sure which library I should use.
What is better xml.etree or xml.dom, and why?
Please, explain your answers and give arguments.
Also, do you think one of them is going to get deprecated? Which one?
Upvotes: 8
Views: 2380
Reputation: 1123430
Neither will be deprecated.
ElementTree (xml.etree) is a pythonic API to access XML. DOM (xml.dom) is a cross-platform, language independent standard.
Use ElementTree unless you have a compelling reason to use the XML DOM instead. For python code, the ElementTree API is far easier to use than the DOM API.
If you are not averse to installing extra python libraries, you should take a look at the lxml
library as well; it implements the ElementTree API as well, on top of very fast C libraries, and adds a few more options to work with XML effectively.
Upvotes: 13