2000-06-29 19:33:43 +00:00
|
|
|
"""Simple API for XML (SAX) implementation for Python.
|
|
|
|
|
|
|
|
This module provides an implementation of the SAX 2 interface;
|
|
|
|
information about the Java version of the interface can be found at
|
|
|
|
http://www.megginson.com/SAX/. The Python version of the interface is
|
|
|
|
documented at <...>.
|
|
|
|
|
|
|
|
This package contains the following modules:
|
|
|
|
|
2000-09-18 16:31:08 +00:00
|
|
|
handler -- Base classes and constants which define the SAX 2 API for
|
|
|
|
the 'client-side' of SAX for Python.
|
2000-06-29 19:33:43 +00:00
|
|
|
|
2000-09-18 16:31:08 +00:00
|
|
|
saxutils -- Implementation of the convenience classes commonly used to
|
|
|
|
work with SAX.
|
2000-06-29 19:33:43 +00:00
|
|
|
|
2000-09-18 16:31:08 +00:00
|
|
|
xmlreader -- Base classes and constants which define the SAX 2 API for
|
|
|
|
the parsers used with SAX for Python.
|
|
|
|
|
|
|
|
expatreader -- Driver that allows use of the Expat parser with the
|
|
|
|
classes defined in saxlib.
|
2000-06-29 19:33:43 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2000-07-01 13:44:04 +00:00
|
|
|
from handler import ContentHandler, ErrorHandler
|
|
|
|
from expatreader import ExpatParser
|
|
|
|
from _exceptions import SAXException, SAXNotRecognizedException, \
|
2000-09-18 16:31:08 +00:00
|
|
|
SAXParseException, SAXNotSupportedException
|
|
|
|
|
2000-07-01 04:58:47 +00:00
|
|
|
|
2000-09-18 16:31:08 +00:00
|
|
|
def parse(filename_or_stream, handler, errorHandler=ErrorHandler()):
|
|
|
|
parser = ExpatParser()
|
|
|
|
parser.setContentHandler(handler)
|
|
|
|
parser.setErrorHandler(errorHandler)
|
|
|
|
parser.parse(filename_or_stream)
|
2000-07-01 04:58:47 +00:00
|
|
|
|
2000-09-18 16:31:08 +00:00
|
|
|
|
|
|
|
def parseString(string, handler, errorHandler=ErrorHandler()):
|
2000-07-01 04:58:47 +00:00
|
|
|
try:
|
2000-09-18 16:31:08 +00:00
|
|
|
from cStringIO import StringIO
|
2000-07-01 04:58:47 +00:00
|
|
|
except ImportError:
|
2000-09-18 16:31:08 +00:00
|
|
|
from StringIO import StringIO
|
2000-07-01 04:58:47 +00:00
|
|
|
|
2000-09-18 16:31:08 +00:00
|
|
|
if errorHandler is None:
|
|
|
|
errorHandler = ErrorHandler()
|
|
|
|
parser = ExpatParser()
|
|
|
|
parser.setContentHandler(handler)
|
|
|
|
parser.setErrorHandler(errorHandler)
|
|
|
|
parser.parse(StringIO(string))
|