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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
lxmllibrary 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.