Name
parse
Synopsis
parse(file,handler,error_handler=None)
file is a filename or a file-like object
open for reading, containing an XML document.
handler is generally an instance of your
own subclass of class ContentHandler, covered
later in this chapter. error_handler, if
given, is generally an instance of your own subclass of class
ErrorHandler. You don’t
necessarily have to subclass ContentHandler and/or
ErrorHandler: you just need to provide the same
interfaces as the classes do. Subclassing is often a convenient means
to this end.
Function parse is equivalent to the code:
p= make_parser( )p.setContentHandler(handler) iferror_handleris not None:p.setErrorHandler(error_handler)p.parse(file)
This idiom is quite frequent in SAX parsing, so having it in a single
function is convenient. When error_handler
is None, the parser diagnoses errors by
propagating an exception that is an instance of some subclass of
SAXException.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access