Name
Convenience Functions
Synopsis
Three important convenience functions make performing a
SAX-based parse trivial. These are sufficient for most applications,
especially if the only handler that’s needed is the ContentHandler
. These functions are provided
in the xml.sax
module and work with
both the standard library and PyXML.
make_parser(
[parser_list]
)
Returns a SAX
XMLReader
object. Most of the examples in Chapter 3 use this function to create a reader. See also Section 3.7, in that chapter, for more information on using the underlying parser factory objects.parse(
source, content_handler[, error_handler]
)
Creates a reader using
make_parser
, associates the provided content and error handlers, and parses an XML document. The document is identified by thesource
parameter, which may be a filename, URL, a file object open for reading, or anInputSource
instance.parseString(
text, content_handler[, error_handler]
)
Similar to
parse
, but the input document is the text given bytext
.
Get Python & XML 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.