Name

ContentHandler

Synopsis

The ContentHandler is the most used of the SAX handler objects. It is this handler that receives information about the elements being parsed, their attributes, and the content between start and end tags. The parse and parseString convenience functions described in the previous section require a ContentHandler implementation to be passed in.

setDocumentLocator( locator )

SAX parsers are encouraged to supply a locator for finding the origin of events within the document, so that you can determine the end position of any document-related event. The locator object conforms to the Locator interface, described later in this Appendix.

startDocument( )

When the parser begins a document, it calls this method first and only once, with the exception of setDocumentLocator, which is called first if implemented.

endDocument( )

This method is called only once as the very last method invoked by the parser.

startPrefixMapping( prefix, uri )

This method is called when a namespace declaration is encountered. The prefix parameter is the prefix string used in the document, and uri refers to the Universal Resource Indicator (URI) that the prefix represents.

endPrefixMapping( prefix )

This event occurs at the time the end element with the corresponding startPrefixMapping is called, indicating that the declaration for prefix has gone out of scope. It does not indicate that there is no mapping for prefix; an outer declaration may still be in scope.

startElement( name, attrs )

This ...

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.