Basics of SAX Programming

SAX programming depends on recognizing events that occur during the process of parsing an XML document.

Parsing Events

In this section, you will use pseudocode to see what happens as an XML document is parsed using a SAX parser.

Listing 18.1 shows a short XML document that you will use to illustrate the SAX approach.

Listing 18.1. SAXSource.xml: A Short XML Document
<?xml version='1.0'?> 
<?xml-stylesheet href="myCSS.css" type="text/css" ?> 
<!-- This is an XML comment. --> 
<myDocument> 
Some text content. 
</myDocument> 

A SAX parser would respond to parsing an XML document like this by signaling events, similar to the following:

 start_document; processing_instruction; start_element (<myDocument>); characters; end_element ...

Get Sams Teach Yourself XML in 10 Minutes 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.