Difference between ElementTree and Minidom

0 votes
What is the difference between the ElementTree and Minidom modules?..Do they parse XML in the same manner?
Jul 22, 2019 in Python by Fata
• 1,050 points
5,738 views

1 answer to this question.

0 votes

Python allows parsing these XML documents using two modules namely, the xml.etree.ElementTree module and Minidom (Minimal DOM Implementation). Parsing means to read information from a file and split it into pieces by identifying parts of that particular XML file.

xml.etree.ElementTree Module:

This module helps us format XML data in a tree structure which is the most natural representation of hierarchical data. 

EXAMPLE:

import xml.etree.ElementTree as ET

mytree = ET.parse('sample.xml')

myroot = mytree.getroot()

print(myroot)

OUTPUT:  <Element ‘metadata’ at 0x033589F0>

xml.dom.minidom Module:

This module is basically used by people who are proficient with DOM (Document Object module). DOM applications often start by parsing XML into DOM.

EXAMPLE:

from xml.dom import minidom

dat=minidom.parse('sample.xml')

print(dat)

OUTPUT: <xml.dom.minidom.Document object at 0x03B5A308>

If you can notice the difference between the outputs, mindom creates an DOM object whereas ElementeTree creates elements.

answered Jul 22, 2019 by Wajiha
• 1,960 points

Related Questions In Python

0 votes
1 answer

What's the difference in Qt between setVisible, setShown and show/hide

show() is just a convenience function for ...READ MORE

answered Apr 17, 2018 in Python by anonymous
8,071 views
0 votes
1 answer

What is the difference between list and tuple?

Lists are mutable(values can be changed) whereas ...READ MORE

answered May 5, 2018 in Python by aayushi
• 750 points
7,029 views
0 votes
1 answer

Difference between '==' and 'is'

'==' checks for the equality of the ...READ MORE

answered May 14, 2018 in Python by Nietzsche's daemon
• 4,260 points
804 views
0 votes
1 answer

Difference between pop and delete methods

I think you mean del() and not ...READ MORE

answered Jun 25, 2018 in Python by Hamartia's Mask
• 1,580 points
2,138 views
+1 vote
2 answers

What is the difference between classes and labels in machine learning?

Classes and Labels both are almost same things ...READ MORE

answered Apr 3, 2019 in Python by SA
• 1,090 points
7,746 views
0 votes
1 answer

What is the difference between Python and IPython?

There are few differences between Python and ...READ MORE

answered Jul 26, 2018 in Python by Priyaj
• 58,020 points
4,039 views
0 votes
1 answer

Difference between del, remove and pop on lists

es, remove removes the first matching value, ...READ MORE

answered Aug 1, 2018 in Python by Priyaj
• 58,020 points
1,099 views
0 votes
1 answer

'NodeList' object has no attribute 'firstChild'

Use the following piece of code: from xml.dom ...READ MORE

answered Jul 22, 2019 in Python by Wajiha
• 1,960 points
4,504 views
0 votes
1 answer

Difference between function and generator?

Normal Functions vs Generator Functions: Generators in Python ...READ MORE

answered Jul 15, 2019 in Python by Wajiha
• 1,960 points
4,943 views
0 votes
1 answer

Difference between end and sep

end and sep are optional parameters of ...READ MORE

answered Jul 30, 2019 in Python by Wajiha
• 1,960 points
24,754 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP