Simon Pepping
Published 19 January 1999
| Revision History | ||
|---|---|---|
| Revision 0.3 | 27 December 1998 | |
| Initial publication | ||
| Revision 0.4 | 31 December 1998 | |
| Small change in how to specify a SAX driver file | ||
| Revision 0.5 | 19 January 1999 | |
| Several changes suggested by Lars M. Garshol | ||
I give a short overview of the Simple API for XML (SAX). I describe how a SAX-compliant parser and a SAX application interact, and how one should proceed to write a SAX application. The description focuses on the Python implementation of SAX. The examples are written in Python.
Write DocumentHandler, DTDHandler, EntityResolver, and ErrorHandler classes.
Select a SAX-compliant parser. E.g.,
SAXparser=xml.sax.drivers.drv_xmlproc.SAX_XPParser(). |
Register the handlers with the parser. E.g.,
SAXparser.setDocumentHandler(DocumentHandler())
SAXparser.setErrorHandler(ErrorHandler()) |
Run the parser by calling its parse method. E.g.,
SAXparser.parse(sys.argv[1]) |
Watch the result, which is completely determined by the handlers of your application.
| Next | ||
| Scheme of the interaction between an application and an XML parser |