Working with minidom
Explore how to use Python's minidom module to parse XML files, extract elements like appointments and book titles, and handle XML data in Python programs. This lesson guides you through reading XML content, managing nodes, and processing text to help you work confidently with XML in Python.
We'll cover the following...
To start out, well need some actual XML to parse. Take a look at the following short example of XML:
This is fairly typical XML and actually pretty intuitive to read. There is some really nasty XML out in the wild that you may have to work with. Anyway, save the XML code above with the following name: appt.xml
Let’s spend some time getting acquainted with how to parse this file using Python’s minidom module. This is a fairly long piece of code, so prepare yourself.
This code is loosely based on an example from the Python documentation and I have to admit that I think my mutation of it is a bit ugly. Let’s break this code down a bit. The url parameter you see in the ApptParser ...