1 \section{\module{xml.sax
} ---
2 Support for SAX2 parsers
}
4 \declaremodule{standard
}{xml.sax
}
5 \modulesynopsis{Package containing SAX2 base classes and convenience
7 \moduleauthor{Lars Marius Garshol
}{larsga@garshol.priv.no
}
8 \sectionauthor{Fred L. Drake, Jr.
}{fdrake@acm.org
}
13 The
\module{xml.sax
} package provides a number of modules which
14 implement the Simple API for XML (SAX) interface for Python. The
15 package itself provides the SAX exceptions and the convenience
16 functions which will be most used by users of the SAX API.
18 The convenience functions are:
20 \begin{funcdesc
}{make_parser
}{\optional{parser_list
}}
21 Create and return a SAX
\class{XMLReader
} object. The first parser
22 found will be used. If
\var{parser_list
} is provided, it must be a
23 sequence of strings which name modules that have a function named
24 \function{create_parser()
}. Modules listed in
\var{parser_list
}
25 will be used before modules in the default list of parsers.
28 \begin{funcdesc
}{parse
}{filename_or_stream, handler
\optional{, error_handler
}}
29 Create a SAX parser and use it to parse a
document. The
document,
30 passed in as
\var{filename_or_stream
}, can be a filename or a file
31 object. The
\var{handler
} parameter needs to be a SAX
32 \class{ContentHandler
} instance. If
\var{error_handler
} is given,
33 it must be a SAX
\class{ErrorHandler
} instance; if omitted,
34 \exception{SAXParseException
} will be raised on all errors. There
35 is no return value; all work must be done by the
\var{handler
}
39 \begin{funcdesc
}{parseString
}{string, handler
\optional{, error_handler
}}
40 Similar to
\function{parse()
}, but parses from a buffer
\var{string
}
41 received as a parameter.
45 The SAX exceptions are also provided here:
47 \begin{excclassdesc
}{SAXException
}{msg
\optional{, exception
}}
48 Encapsulate an XML error or warning. This class can contain basic
49 error or warning information from either the XML parser or the
50 application: it can be subclassed to provide additional
51 functionality or to add localization. Note that although the
52 handlers defined in the
\class{ErrorHandler
} interface receive
53 instances of this exception, it is not required to actually raise
54 the exception --- it is also useful as a container for information.
56 When instantiated,
\var{msg
} should be a human-readable description
57 of the error. The optional
\var{exception
} parameter, if given,
58 should be
\code{None
} or an exception that was caught by the parsing
59 code and is being passed along as information.
61 This is the base class for the other SAX exception classes.
64 \begin{excclassdesc
}{SAXParseException
}{msg, exception, locator
}
65 Subclass of
\exception{SAXException
} raised on parse errors.
66 Instances of this class are passed to the methods of the SAX
67 \class{ErrorHandler
} interface to provide information about the
68 parse error. This class supports the SAX
\class{Locator
} interface
69 as well as the
\class{SAXException
} interface.
72 \begin{excclassdesc
}{SAXNotRecognizedException
}{msg
\optional{, exception
}}
73 Subclass of
\exception{SAXException
} raised when a SAX
74 \class{XMLReader
} is confronted with an unrecognized feature or
75 property. SAX applications and extensions may use this class for
79 \begin{excclassdesc
}{SAXNotSupportedException
}{msg
\optional{, exception
}}
80 Subclass of
\exception{SAXException
} raised when a SAX
81 \class{XMLReader
} is asked to enable a feature that is not
82 supported, or to set a property to a value that the implementation
83 does not support. SAX applications and extensions may use this
84 class for similar purposes.
89 \seetitle[http://www.megginson.com/SAX/
]{SAX: The Simple API for
90 XML
}{This site is the focal point for the definition of
91 the SAX API. It provides a Java implementation and online
92 documentation. Links to implementations and historical
93 information are also available.
}
97 \subsection{SAXException Objects
\label{saxexception-objects
}}
99 The
\class{SAXException
} exception class supports the following
102 \begin{methoddesc
}[SAXException
]{getMessage
}{}
103 Return a human-readable message describing the error condition.
106 \begin{methoddesc
}[SAXException
]{getException
}{}
107 Return an encapsulated exception object, or
\code{None
}.