From the course: Python: XML, JSON, and the Web

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using the xml.sax module

Using the xml.sax module - Python Tutorial

From the course: Python: XML, JSON, and the Web

Start my 1-month free trial

Using the xml.sax module

- [Narrator] Okay, let's take what we've learned so far and put it to use. In this example, we're going to retrieve XML data from a web server, parse it using SAX and then output some interesting information about the data. So in VS Code, I'm going to open up the file, sax_parse_start.py which is in my XML SAX chapter. And before we do anything, let's just take a look at the code. So I'll scroll down to the main function. Here in the main function, I have a variable named handler. And it's being set to an instance of my content handler class. And then, I'm using the httpbin.org site, the XML endpoint to get some sample XML data to work on. And here you can see I'm using the requests library to request the data and let's take a look, we scroll back up to the my content handler class. So you can see I'm importing the XML SAX module. And I've declared a class named my MyContentHandler which is a subclass of the SAX content handler base class. And I'm gonna record some information about…

Contents