Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xml.etree or xml.dom?

Tags:

python

xml

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?

like image 624
user1586464 Avatar asked Aug 14 '12 12:08

user1586464


People also ask

What is XML Etree?

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.

What is an XML DOM?

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.

What is DOM in XML How is it different from XML schemas?

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.

What is the difference between HTML DOM and XML DOM?

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.


1 Answers

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.

like image 134
Martijn Pieters Avatar answered Sep 23 '22 15:09

Martijn Pieters