Back to top
libxmlop is a SAX2 driver for PyXML. It is implemented on top of the libxml XML parser.
libxmlop exposes the standard Python SAX2 interface and callbacks plus a few additional capabilities, which are described below.
You can learn more about libxml at http://xmlsoft.org/.
Back to top
Note that on my machine I had to add the directory containing the installed libraries to the environment variable LD_LIBRARY_PATH. For example:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
NOTE! The following replaces setup.py. If you have modified that file or have a version other than PyXML-0.7, you may want to patch in the libxmlop stanza instead.
cd /Python/PyXML-0.7 unzip ../libxmlop.zip
python setup.py build python setup.py install
Use that standard Python SAX2 interface.
Back to toplibxmlop provides the following functions not provided by the standard SAX2 interface.
Turn a SAX2 callback off or on. After turning a call-back off, the content handler will not receive events for that call-back.
Prototype:
parser.activateEventHandler(callback_name, flag)
Where:
Example:
import xml.sax class ContentHandler: def __init__(self, parser): self.parser = parser self.target = '' def startDocument(self): self.parser.activateEventHandler('characters', 0) def startElement(self, name, attrs): if name == 'target': self.parser.activateEventHandler('characters', 1) def endElement(self, name, attrs): if name == 'target': self.parser.activateEventHandler('characters', 0) def characters(self, data): self.target += data def test(inFileName): parser = xml.sax.make_parser('xml.sax.drivers2.drv_libxmlop') handler = ContentHandler(parser) parser.setContentHandler(handler) parser.parse(inFileName)Back to top
You can find more information about libxml at http://xmlsoft.org.
More information about PyXML is at http://www.python.org/sigs/xml-sig/.
Back to topLast update: 4/11/02
Dave Kuhlman