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?
The xml.etree.ElementTree module implements a simple and efficient API for parsing and creating XML data. Changed in version 3.3: This module will use a fast implementation whenever available.
The XML Document Object Model (DOM) class is an in-memory representation of an XML document. The DOM allows you to programmatically read, manipulate, and modify an XML document. The XmlReader class also reads XML; however, it provides non-cached, forward-only, read-only access.
DOM is an acronym stands for Document Object Model. It defines a standard way to access and manipulate documents. The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.
The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an HTML document as a tree-structure. The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With