In this tutorial, you learned about one of the two popular APIs for parsing XML filesSAX. You already covered the DOM in the previous lesson, so this lesson wrapped up some loose ends in terms of giving you a more rounded understanding of XML parsing. SAX (Simple API for XML) is an event-driven parser that is usually combined with a custom program designed to process the events generated by the parser. You worked through an example of such an application in this tutorial that demonstrated how to use the Xerces SAX parser to iterate through the entities in an XML document and print out detailed information about them.


I didn't get any of that Java stuff; how am I supposed to use SAX?

If you found the Java code confusing, you may be better off looking at the documentation for the SAX implementation for a programming language that you're more comfortable using. You may want to do some online investigating to find a SAX parser that's appropriate for you. Keep in mind that the Xerces SAX parser (http://xml.apache.org/) that you used in this lesson is also available for the C++ and Perl languages. Also, if you prefer using JavaScript or Visual Basic you may want to consider using the DOM for XML processing, which you explored in What is the DOM, "Parsing XML with the DOM."

How do I access the data structure created by SAX?

The catch with SAX is that it doesn't create its own data structure; it's up to the programmer who writes the event handlers to generate a data structure, print the XML, or do whatever it is they want to do with the data as it's processed by the SAX parser.


The Workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put your knowledge into practice.



What is an event-driven parser?


What standards body was responsible for the creation of SAX?


Which important feature was added when SAX was upgraded from version 1.0 to 2.0?

Quiz Answers


An event-driven parser iterates through an XML document and calls specific methods in another program as it processes entities in the document being parsed.


I admit it, this was a trick question; a standards body did not create SAX. Rather, members of the xml-dev mailing list created it through a grassroots effort.


SAX 2.0 added support for namespaces.



Modify the sample program in this tutorial so that it reproduces the XML document that is supplied as input.


Reproduce the sample program in the language that you do your development in (if it's not Java).