Creating a SAX-Parsing Application

Now that the JAXP APIs are set up, let's begin the task of creating an application that uses a SAX parser to parse an XML file.

Creating the CarParts.xml File

In this chapter, an XML file that describes the parts of a car will be used as an example. The XML file will be named CarParts.xml. To create it, open the text editor of your choice, copy the following code, and save the file as CarParts.xml:

<?xml version='1.0'?>
<!-- XML file that describes car parts -->
<carparts>
    <engine>
    </engine>
    <carbody>
    </carbody>
    <wheel>
    </wheel>
    <carstereo>
    </carstereo>
</carparts>

Before proceeding to write the application code, let's briefly examine the XML file. The first line

<?xml version='1.0'?>

identifies the file ...

Get Java™ APIs for XML Kick Start 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.