Parsing XML

We'll cover the following...

Python can parse XML documents in several ways. It has traditional DOM and SAX parsers, but I will focus on a different library called ElementTree.

Press + to interact
import xml.etree.ElementTree as etree #①
tree = etree.parse('feed.xml') #②
root = tree.getroot() #③
root #④
#<Element {http://www.w3.org/2005/Atom}feed at cd1eb0>

① The ElementTree library is part of the Python standard library, in xml.etree.ElementTree.

② The primary entry point for the ElementTree library is the parse() function, which can take a filename or a ...

Access this course and 1400+ top-rated courses and projects.