Using the XML module to parse XML data

In this next section, I will walk through some of the steps for using Python to parse and process XML data in a basic project to convert a dataset from XML to JSON.

In Python, XML is represented using a tree-like structure and parsed using the xml.etree.ElementTree module. Navigating this tree is a bit more sophisticated than navigating the structure of JSON data because the structure of XML does not fit as neatly into python data structures. 

The first step to processing XML data is to read the XML data into Python's tree-like XML representation with the xml.etree.ElementTree module, using the following steps:

  1. Import the xml.etree.ElementTree module.
  2. Open the file containing the XML data.
  3. Use the ...

Get Practical Data Wrangling now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.