10.10. Switching SAX Parsers

As mentioned at the start of this chapter, one of the big advantages of basing an XML application on SAX is that you can switch from XML parser to XML parser without making code changes.

In the demonstration programs of this chapter, you have seen numerous calls to the make_parser function provided in the saxexts (SAX extensions) module.

CD-ROM reference=10036.txt
parser = saxexts.make_parser()

When invoked with no parameters, make_parser will return the first SAX-compliant parser it finds installed. You can specify a parser to use by giving its name as a parameter to the make_parser call. In the example below, James Clark's expat parser is selected.

 CD-ROM reference=10037.txt parser = saxexts.make_parser("xml.sax.drivers.drv_pyexpat") ...

Get XML Processing with Python 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.