10.9. SAX as a Source of PYX

We now have covered all the material on SAX required to build a SAX application that generates PYX. This facility will be part of the Pyxie library later on, but a standalone version of the routine is shown here to illustrate a SAX application.

 CD-ROM reference=10034.txt #! /usr/bin/env python """ Utility to create PYX notation from the default SAX-compliant parser Sean Mc Grath XML Processing with Python """ # Import the SAX modules. from xml.sax import saxexts, saxlib, saxutils import string def Encode (s): """ Convert line ends to the two character sequence '\' followed by 'n'. """ return string.replace (s,"\n","\\n") class myHandler (saxlib.DocumentHandler): def startElement(self,Element,Attributes): print "(%s" ...

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.