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.

XML parsing models

XML parsing models - Python Tutorial

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

Start my 1-month free trial

XML parsing models

- Okay, now it's time to start looking at XML. Before we can start learning about how to work with XML data in Python, we first have to understand the different ways that XML can be parsed. There are, essentially, two main ways that XML parsers work. The first way is known as the Simple API for XML, which is often just referred to as SAX. The second method is called the Document Object Model or simply known as the DOM. And if you've done any web development, you've probably heard that term, before. So, in this chapter, we're going to focus on the SAX API and we'll get to the DOM later in the course. A parser that uses the SAX method works like an assembly line. It reads the XML data one character at a time until the entire file has been read. While the XML data is being read, the parser generates various events that correspond to the content of the XML, so your Python app defines a class that will handle these events as they come in. So, let's look at a simple example. So, consider…

Contents