Interface for receiving logical document content events. This is the main callback interface in SAX, and the one most important to applications. The order of events in this interface mirrors the order of the information in the document.
| 43 | # ===== CONTENTHANDLER ===== |
| 44 | |
| 45 | class ContentHandler: |
| 46 | """Interface for receiving logical document content events. |
| 47 | |
| 48 | This is the main callback interface in SAX, and the one most |
| 49 | important to applications. The order of events in this interface |
| 50 | mirrors the order of the information in the document.""" |
| 51 | |
| 52 | def __init__(self): |
| 53 | self._locator = None |
| 54 | |
| 55 | def setDocumentLocator(self, locator): |
| 56 | """Called by the parser to give the application a locator for |
| 57 | locating the origin of document events. |
| 58 | |
| 59 | SAX parsers are strongly encouraged (though not absolutely |
| 60 | required) to supply a locator: if it does so, it must supply |
| 61 | the locator to the application by invoking this method before |
| 62 | invoking any of the other methods in the DocumentHandler |
| 63 | interface. |
| 64 | |
| 65 | The locator allows the application to determine the end |
| 66 | position of any document-related event, even if the parser is |
| 67 | not reporting an error. Typically, the application will use |
| 68 | this information for reporting its own errors (such as |
| 69 | character content that does not match an application's |
| 70 | business rules). The information returned by the locator is |
| 71 | probably not sufficient for use with a search engine. |
| 72 | |
| 73 | Note that the locator will return correct information only |
| 74 | during the invocation of the events in this interface. The |
| 75 | application should not attempt to use it at any other time.""" |
| 76 | self._locator = locator |
| 77 | |
| 78 | def startDocument(self): |
| 79 | """Receive notification of the beginning of a document. |
| 80 | |
| 81 | The SAX parser will invoke this method only once, before any |
| 82 | other methods in this interface or in DTDHandler (except for |
| 83 | setDocumentLocator).""" |
| 84 | |
| 85 | def endDocument(self): |
| 86 | """Receive notification of the end of a document. |
| 87 | |
| 88 | The SAX parser will invoke this method only once, and it will |
| 89 | be the last method invoked during the parse. The parser shall |
| 90 | not invoke this method until it has either abandoned parsing |
| 91 | (because of an unrecoverable error) or reached the end of |
| 92 | input.""" |
| 93 | |
| 94 | def startPrefixMapping(self, prefix, uri): |
| 95 | """Begin the scope of a prefix-URI Namespace mapping. |
| 96 | |
| 97 | The information from this event is not necessary for normal |
| 98 | Namespace processing: the SAX XML reader will automatically |
| 99 | replace prefixes for element and attribute names when the |
| 100 | http://xml.org/sax/features/namespaces feature is true (the |
| 101 | default). |
| 102 |
no outgoing calls
searching dependent graphs…