17db96d56Sopenharmony_ci:mod:`xml.sax.handler` --- Base classes for SAX handlers
27db96d56Sopenharmony_ci========================================================
37db96d56Sopenharmony_ci
47db96d56Sopenharmony_ci.. module:: xml.sax.handler
57db96d56Sopenharmony_ci   :synopsis: Base classes for SAX event handlers.
67db96d56Sopenharmony_ci
77db96d56Sopenharmony_ci.. moduleauthor:: Lars Marius Garshol <larsga@garshol.priv.no>
87db96d56Sopenharmony_ci.. sectionauthor:: Martin v. Löwis <martin@v.loewis.de>
97db96d56Sopenharmony_ci
107db96d56Sopenharmony_ci**Source code:** :source:`Lib/xml/sax/handler.py`
117db96d56Sopenharmony_ci
127db96d56Sopenharmony_ci--------------
137db96d56Sopenharmony_ci
147db96d56Sopenharmony_ciThe SAX API defines five kinds of handlers: content handlers, DTD handlers,
157db96d56Sopenharmony_cierror handlers, entity resolvers and lexical handlers. Applications normally
167db96d56Sopenharmony_cionly need to implement those interfaces whose events they are interested in;
177db96d56Sopenharmony_cithey can implement the interfaces in a single object or in multiple objects.
187db96d56Sopenharmony_ciHandler implementations should inherit from the base classes provided in the
197db96d56Sopenharmony_cimodule :mod:`xml.sax.handler`, so that all methods get default implementations.
207db96d56Sopenharmony_ci
217db96d56Sopenharmony_ci
227db96d56Sopenharmony_ci.. class:: ContentHandler
237db96d56Sopenharmony_ci
247db96d56Sopenharmony_ci   This is the main callback interface in SAX, and the one most important to
257db96d56Sopenharmony_ci   applications. The order of events in this interface mirrors the order of the
267db96d56Sopenharmony_ci   information in the document.
277db96d56Sopenharmony_ci
287db96d56Sopenharmony_ci
297db96d56Sopenharmony_ci.. class:: DTDHandler
307db96d56Sopenharmony_ci
317db96d56Sopenharmony_ci   Handle DTD events.
327db96d56Sopenharmony_ci
337db96d56Sopenharmony_ci   This interface specifies only those DTD events required for basic parsing
347db96d56Sopenharmony_ci   (unparsed entities and attributes).
357db96d56Sopenharmony_ci
367db96d56Sopenharmony_ci
377db96d56Sopenharmony_ci.. class:: EntityResolver
387db96d56Sopenharmony_ci
397db96d56Sopenharmony_ci   Basic interface for resolving entities. If you create an object implementing
407db96d56Sopenharmony_ci   this interface, then register the object with your Parser, the parser will call
417db96d56Sopenharmony_ci   the method in your object to resolve all external entities.
427db96d56Sopenharmony_ci
437db96d56Sopenharmony_ci
447db96d56Sopenharmony_ci.. class:: ErrorHandler
457db96d56Sopenharmony_ci
467db96d56Sopenharmony_ci   Interface used by the parser to present error and warning messages to the
477db96d56Sopenharmony_ci   application.  The methods of this object control whether errors are immediately
487db96d56Sopenharmony_ci   converted to exceptions or are handled in some other way.
497db96d56Sopenharmony_ci
507db96d56Sopenharmony_ci
517db96d56Sopenharmony_ci.. class:: LexicalHandler
527db96d56Sopenharmony_ci
537db96d56Sopenharmony_ci   Interface used by the parser to represent low frequency events which may not
547db96d56Sopenharmony_ci   be of interest to many applications.
557db96d56Sopenharmony_ci
567db96d56Sopenharmony_ciIn addition to these classes, :mod:`xml.sax.handler` provides symbolic constants
577db96d56Sopenharmony_cifor the feature and property names.
587db96d56Sopenharmony_ci
597db96d56Sopenharmony_ci
607db96d56Sopenharmony_ci.. data:: feature_namespaces
617db96d56Sopenharmony_ci
627db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/features/namespaces"``
637db96d56Sopenharmony_ci   | true: Perform Namespace processing.
647db96d56Sopenharmony_ci   | false: Optionally do not perform Namespace processing (implies
657db96d56Sopenharmony_ci     namespace-prefixes; default).
667db96d56Sopenharmony_ci   | access: (parsing) read-only; (not parsing) read/write
677db96d56Sopenharmony_ci
687db96d56Sopenharmony_ci
697db96d56Sopenharmony_ci.. data:: feature_namespace_prefixes
707db96d56Sopenharmony_ci
717db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/features/namespace-prefixes"``
727db96d56Sopenharmony_ci   | true: Report the original prefixed names and attributes used for Namespace
737db96d56Sopenharmony_ci     declarations.
747db96d56Sopenharmony_ci   | false: Do not report attributes used for Namespace declarations, and
757db96d56Sopenharmony_ci     optionally do not report original prefixed names (default).
767db96d56Sopenharmony_ci   | access: (parsing) read-only; (not parsing) read/write
777db96d56Sopenharmony_ci
787db96d56Sopenharmony_ci
797db96d56Sopenharmony_ci.. data:: feature_string_interning
807db96d56Sopenharmony_ci
817db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/features/string-interning"``
827db96d56Sopenharmony_ci   | true: All element names, prefixes, attribute names, Namespace URIs, and
837db96d56Sopenharmony_ci     local names are interned using the built-in intern function.
847db96d56Sopenharmony_ci   | false: Names are not necessarily interned, although they may be (default).
857db96d56Sopenharmony_ci   | access: (parsing) read-only; (not parsing) read/write
867db96d56Sopenharmony_ci
877db96d56Sopenharmony_ci
887db96d56Sopenharmony_ci.. data:: feature_validation
897db96d56Sopenharmony_ci
907db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/features/validation"``
917db96d56Sopenharmony_ci   | true: Report all validation errors (implies external-general-entities and
927db96d56Sopenharmony_ci     external-parameter-entities).
937db96d56Sopenharmony_ci   | false: Do not report validation errors.
947db96d56Sopenharmony_ci   | access: (parsing) read-only; (not parsing) read/write
957db96d56Sopenharmony_ci
967db96d56Sopenharmony_ci
977db96d56Sopenharmony_ci.. data:: feature_external_ges
987db96d56Sopenharmony_ci
997db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/features/external-general-entities"``
1007db96d56Sopenharmony_ci   | true: Include all external general (text) entities.
1017db96d56Sopenharmony_ci   | false: Do not include external general entities.
1027db96d56Sopenharmony_ci   | access: (parsing) read-only; (not parsing) read/write
1037db96d56Sopenharmony_ci
1047db96d56Sopenharmony_ci
1057db96d56Sopenharmony_ci.. data:: feature_external_pes
1067db96d56Sopenharmony_ci
1077db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/features/external-parameter-entities"``
1087db96d56Sopenharmony_ci   | true: Include all external parameter entities, including the external DTD
1097db96d56Sopenharmony_ci     subset.
1107db96d56Sopenharmony_ci   | false: Do not include any external parameter entities, even the external
1117db96d56Sopenharmony_ci     DTD subset.
1127db96d56Sopenharmony_ci   | access: (parsing) read-only; (not parsing) read/write
1137db96d56Sopenharmony_ci
1147db96d56Sopenharmony_ci
1157db96d56Sopenharmony_ci.. data:: all_features
1167db96d56Sopenharmony_ci
1177db96d56Sopenharmony_ci   List of all features.
1187db96d56Sopenharmony_ci
1197db96d56Sopenharmony_ci
1207db96d56Sopenharmony_ci.. data:: property_lexical_handler
1217db96d56Sopenharmony_ci
1227db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/properties/lexical-handler"``
1237db96d56Sopenharmony_ci   | data type: xml.sax.handler.LexicalHandler (not supported in Python 2)
1247db96d56Sopenharmony_ci   | description: An optional extension handler for lexical events like
1257db96d56Sopenharmony_ci     comments.
1267db96d56Sopenharmony_ci   | access: read/write
1277db96d56Sopenharmony_ci
1287db96d56Sopenharmony_ci
1297db96d56Sopenharmony_ci.. data:: property_declaration_handler
1307db96d56Sopenharmony_ci
1317db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/properties/declaration-handler"``
1327db96d56Sopenharmony_ci   | data type: xml.sax.sax2lib.DeclHandler (not supported in Python 2)
1337db96d56Sopenharmony_ci   | description: An optional extension handler for DTD-related events other
1347db96d56Sopenharmony_ci     than notations and unparsed entities.
1357db96d56Sopenharmony_ci   | access: read/write
1367db96d56Sopenharmony_ci
1377db96d56Sopenharmony_ci
1387db96d56Sopenharmony_ci.. data:: property_dom_node
1397db96d56Sopenharmony_ci
1407db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/properties/dom-node"``
1417db96d56Sopenharmony_ci   | data type: org.w3c.dom.Node (not supported in Python 2)
1427db96d56Sopenharmony_ci   | description: When parsing, the current DOM node being visited if this is
1437db96d56Sopenharmony_ci     a DOM iterator; when not parsing, the root DOM node for iteration.
1447db96d56Sopenharmony_ci   | access: (parsing) read-only; (not parsing) read/write
1457db96d56Sopenharmony_ci
1467db96d56Sopenharmony_ci
1477db96d56Sopenharmony_ci.. data:: property_xml_string
1487db96d56Sopenharmony_ci
1497db96d56Sopenharmony_ci   | value: ``"http://xml.org/sax/properties/xml-string"``
1507db96d56Sopenharmony_ci   | data type: Bytes
1517db96d56Sopenharmony_ci   | description: The literal string of characters that was the source for the
1527db96d56Sopenharmony_ci     current event.
1537db96d56Sopenharmony_ci   | access: read-only
1547db96d56Sopenharmony_ci
1557db96d56Sopenharmony_ci
1567db96d56Sopenharmony_ci.. data:: all_properties
1577db96d56Sopenharmony_ci
1587db96d56Sopenharmony_ci   List of all known property names.
1597db96d56Sopenharmony_ci
1607db96d56Sopenharmony_ci
1617db96d56Sopenharmony_ci.. _content-handler-objects:
1627db96d56Sopenharmony_ci
1637db96d56Sopenharmony_ciContentHandler Objects
1647db96d56Sopenharmony_ci----------------------
1657db96d56Sopenharmony_ci
1667db96d56Sopenharmony_ciUsers are expected to subclass :class:`ContentHandler` to support their
1677db96d56Sopenharmony_ciapplication.  The following methods are called by the parser on the appropriate
1687db96d56Sopenharmony_cievents in the input document:
1697db96d56Sopenharmony_ci
1707db96d56Sopenharmony_ci
1717db96d56Sopenharmony_ci.. method:: ContentHandler.setDocumentLocator(locator)
1727db96d56Sopenharmony_ci
1737db96d56Sopenharmony_ci   Called by the parser to give the application a locator for locating the origin
1747db96d56Sopenharmony_ci   of document events.
1757db96d56Sopenharmony_ci
1767db96d56Sopenharmony_ci   SAX parsers are strongly encouraged (though not absolutely required) to supply a
1777db96d56Sopenharmony_ci   locator: if it does so, it must supply the locator to the application by
1787db96d56Sopenharmony_ci   invoking this method before invoking any of the other methods in the
1797db96d56Sopenharmony_ci   DocumentHandler interface.
1807db96d56Sopenharmony_ci
1817db96d56Sopenharmony_ci   The locator allows the application to determine the end position of any
1827db96d56Sopenharmony_ci   document-related event, even if the parser is not reporting an error. Typically,
1837db96d56Sopenharmony_ci   the application will use this information for reporting its own errors (such as
1847db96d56Sopenharmony_ci   character content that does not match an application's business rules). The
1857db96d56Sopenharmony_ci   information returned by the locator is probably not sufficient for use with a
1867db96d56Sopenharmony_ci   search engine.
1877db96d56Sopenharmony_ci
1887db96d56Sopenharmony_ci   Note that the locator will return correct information only during the invocation
1897db96d56Sopenharmony_ci   of the events in this interface. The application should not attempt to use it at
1907db96d56Sopenharmony_ci   any other time.
1917db96d56Sopenharmony_ci
1927db96d56Sopenharmony_ci
1937db96d56Sopenharmony_ci.. method:: ContentHandler.startDocument()
1947db96d56Sopenharmony_ci
1957db96d56Sopenharmony_ci   Receive notification of the beginning of a document.
1967db96d56Sopenharmony_ci
1977db96d56Sopenharmony_ci   The SAX parser will invoke this method only once, before any other methods in
1987db96d56Sopenharmony_ci   this interface or in DTDHandler (except for :meth:`setDocumentLocator`).
1997db96d56Sopenharmony_ci
2007db96d56Sopenharmony_ci
2017db96d56Sopenharmony_ci.. method:: ContentHandler.endDocument()
2027db96d56Sopenharmony_ci
2037db96d56Sopenharmony_ci   Receive notification of the end of a document.
2047db96d56Sopenharmony_ci
2057db96d56Sopenharmony_ci   The SAX parser will invoke this method only once, and it will be the last method
2067db96d56Sopenharmony_ci   invoked during the parse. The parser shall not invoke this method until it has
2077db96d56Sopenharmony_ci   either abandoned parsing (because of an unrecoverable error) or reached the end
2087db96d56Sopenharmony_ci   of input.
2097db96d56Sopenharmony_ci
2107db96d56Sopenharmony_ci
2117db96d56Sopenharmony_ci.. method:: ContentHandler.startPrefixMapping(prefix, uri)
2127db96d56Sopenharmony_ci
2137db96d56Sopenharmony_ci   Begin the scope of a prefix-URI Namespace mapping.
2147db96d56Sopenharmony_ci
2157db96d56Sopenharmony_ci   The information from this event is not necessary for normal Namespace
2167db96d56Sopenharmony_ci   processing: the SAX XML reader will automatically replace prefixes for element
2177db96d56Sopenharmony_ci   and attribute names when the ``feature_namespaces`` feature is enabled (the
2187db96d56Sopenharmony_ci   default).
2197db96d56Sopenharmony_ci
2207db96d56Sopenharmony_ci   There are cases, however, when applications need to use prefixes in character
2217db96d56Sopenharmony_ci   data or in attribute values, where they cannot safely be expanded automatically;
2227db96d56Sopenharmony_ci   the :meth:`startPrefixMapping` and :meth:`endPrefixMapping` events supply the
2237db96d56Sopenharmony_ci   information to the application to expand prefixes in those contexts itself, if
2247db96d56Sopenharmony_ci   necessary.
2257db96d56Sopenharmony_ci
2267db96d56Sopenharmony_ci   .. XXX This is not really the default, is it? MvL
2277db96d56Sopenharmony_ci
2287db96d56Sopenharmony_ci   Note that :meth:`startPrefixMapping` and :meth:`endPrefixMapping` events are not
2297db96d56Sopenharmony_ci   guaranteed to be properly nested relative to each-other: all
2307db96d56Sopenharmony_ci   :meth:`startPrefixMapping` events will occur before the corresponding
2317db96d56Sopenharmony_ci   :meth:`startElement` event, and all :meth:`endPrefixMapping` events will occur
2327db96d56Sopenharmony_ci   after the corresponding :meth:`endElement` event, but their order is not
2337db96d56Sopenharmony_ci   guaranteed.
2347db96d56Sopenharmony_ci
2357db96d56Sopenharmony_ci
2367db96d56Sopenharmony_ci.. method:: ContentHandler.endPrefixMapping(prefix)
2377db96d56Sopenharmony_ci
2387db96d56Sopenharmony_ci   End the scope of a prefix-URI mapping.
2397db96d56Sopenharmony_ci
2407db96d56Sopenharmony_ci   See :meth:`startPrefixMapping` for details. This event will always occur after
2417db96d56Sopenharmony_ci   the corresponding :meth:`endElement` event, but the order of
2427db96d56Sopenharmony_ci   :meth:`endPrefixMapping` events is not otherwise guaranteed.
2437db96d56Sopenharmony_ci
2447db96d56Sopenharmony_ci
2457db96d56Sopenharmony_ci.. method:: ContentHandler.startElement(name, attrs)
2467db96d56Sopenharmony_ci
2477db96d56Sopenharmony_ci   Signals the start of an element in non-namespace mode.
2487db96d56Sopenharmony_ci
2497db96d56Sopenharmony_ci   The *name* parameter contains the raw XML 1.0 name of the element type as a
2507db96d56Sopenharmony_ci   string and the *attrs* parameter holds an object of the
2517db96d56Sopenharmony_ci   :class:`~xml.sax.xmlreader.Attributes`
2527db96d56Sopenharmony_ci   interface (see :ref:`attributes-objects`) containing the attributes of
2537db96d56Sopenharmony_ci   the element.  The object passed as *attrs* may be re-used by the parser; holding
2547db96d56Sopenharmony_ci   on to a reference to it is not a reliable way to keep a copy of the attributes.
2557db96d56Sopenharmony_ci   To keep a copy of the attributes, use the :meth:`copy` method of the *attrs*
2567db96d56Sopenharmony_ci   object.
2577db96d56Sopenharmony_ci
2587db96d56Sopenharmony_ci
2597db96d56Sopenharmony_ci.. method:: ContentHandler.endElement(name)
2607db96d56Sopenharmony_ci
2617db96d56Sopenharmony_ci   Signals the end of an element in non-namespace mode.
2627db96d56Sopenharmony_ci
2637db96d56Sopenharmony_ci   The *name* parameter contains the name of the element type, just as with the
2647db96d56Sopenharmony_ci   :meth:`startElement` event.
2657db96d56Sopenharmony_ci
2667db96d56Sopenharmony_ci
2677db96d56Sopenharmony_ci.. method:: ContentHandler.startElementNS(name, qname, attrs)
2687db96d56Sopenharmony_ci
2697db96d56Sopenharmony_ci   Signals the start of an element in namespace mode.
2707db96d56Sopenharmony_ci
2717db96d56Sopenharmony_ci   The *name* parameter contains the name of the element type as a ``(uri,
2727db96d56Sopenharmony_ci   localname)`` tuple, the *qname* parameter contains the raw XML 1.0 name used in
2737db96d56Sopenharmony_ci   the source document, and the *attrs* parameter holds an instance of the
2747db96d56Sopenharmony_ci   :class:`~xml.sax.xmlreader.AttributesNS` interface (see
2757db96d56Sopenharmony_ci   :ref:`attributes-ns-objects`)
2767db96d56Sopenharmony_ci   containing the attributes of the element.  If no namespace is associated with
2777db96d56Sopenharmony_ci   the element, the *uri* component of *name* will be ``None``.  The object passed
2787db96d56Sopenharmony_ci   as *attrs* may be re-used by the parser; holding on to a reference to it is not
2797db96d56Sopenharmony_ci   a reliable way to keep a copy of the attributes.  To keep a copy of the
2807db96d56Sopenharmony_ci   attributes, use the :meth:`copy` method of the *attrs* object.
2817db96d56Sopenharmony_ci
2827db96d56Sopenharmony_ci   Parsers may set the *qname* parameter to ``None``, unless the
2837db96d56Sopenharmony_ci   ``feature_namespace_prefixes`` feature is activated.
2847db96d56Sopenharmony_ci
2857db96d56Sopenharmony_ci
2867db96d56Sopenharmony_ci.. method:: ContentHandler.endElementNS(name, qname)
2877db96d56Sopenharmony_ci
2887db96d56Sopenharmony_ci   Signals the end of an element in namespace mode.
2897db96d56Sopenharmony_ci
2907db96d56Sopenharmony_ci   The *name* parameter contains the name of the element type, just as with the
2917db96d56Sopenharmony_ci   :meth:`startElementNS` method, likewise the *qname* parameter.
2927db96d56Sopenharmony_ci
2937db96d56Sopenharmony_ci
2947db96d56Sopenharmony_ci.. method:: ContentHandler.characters(content)
2957db96d56Sopenharmony_ci
2967db96d56Sopenharmony_ci   Receive notification of character data.
2977db96d56Sopenharmony_ci
2987db96d56Sopenharmony_ci   The Parser will call this method to report each chunk of character data. SAX
2997db96d56Sopenharmony_ci   parsers may return all contiguous character data in a single chunk, or they may
3007db96d56Sopenharmony_ci   split it into several chunks; however, all of the characters in any single event
3017db96d56Sopenharmony_ci   must come from the same external entity so that the Locator provides useful
3027db96d56Sopenharmony_ci   information.
3037db96d56Sopenharmony_ci
3047db96d56Sopenharmony_ci   *content* may be a string or bytes instance; the ``expat`` reader module
3057db96d56Sopenharmony_ci   always produces strings.
3067db96d56Sopenharmony_ci
3077db96d56Sopenharmony_ci   .. note::
3087db96d56Sopenharmony_ci
3097db96d56Sopenharmony_ci      The earlier SAX 1 interface provided by the Python XML Special Interest Group
3107db96d56Sopenharmony_ci      used a more Java-like interface for this method.  Since most parsers used from
3117db96d56Sopenharmony_ci      Python did not take advantage of the older interface, the simpler signature was
3127db96d56Sopenharmony_ci      chosen to replace it.  To convert old code to the new interface, use *content*
3137db96d56Sopenharmony_ci      instead of slicing content with the old *offset* and *length* parameters.
3147db96d56Sopenharmony_ci
3157db96d56Sopenharmony_ci
3167db96d56Sopenharmony_ci.. method:: ContentHandler.ignorableWhitespace(whitespace)
3177db96d56Sopenharmony_ci
3187db96d56Sopenharmony_ci   Receive notification of ignorable whitespace in element content.
3197db96d56Sopenharmony_ci
3207db96d56Sopenharmony_ci   Validating Parsers must use this method to report each chunk of ignorable
3217db96d56Sopenharmony_ci   whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating
3227db96d56Sopenharmony_ci   parsers may also use this method if they are capable of parsing and using
3237db96d56Sopenharmony_ci   content models.
3247db96d56Sopenharmony_ci
3257db96d56Sopenharmony_ci   SAX parsers may return all contiguous whitespace in a single chunk, or they may
3267db96d56Sopenharmony_ci   split it into several chunks; however, all of the characters in any single event
3277db96d56Sopenharmony_ci   must come from the same external entity, so that the Locator provides useful
3287db96d56Sopenharmony_ci   information.
3297db96d56Sopenharmony_ci
3307db96d56Sopenharmony_ci
3317db96d56Sopenharmony_ci.. method:: ContentHandler.processingInstruction(target, data)
3327db96d56Sopenharmony_ci
3337db96d56Sopenharmony_ci   Receive notification of a processing instruction.
3347db96d56Sopenharmony_ci
3357db96d56Sopenharmony_ci   The Parser will invoke this method once for each processing instruction found:
3367db96d56Sopenharmony_ci   note that processing instructions may occur before or after the main document
3377db96d56Sopenharmony_ci   element.
3387db96d56Sopenharmony_ci
3397db96d56Sopenharmony_ci   A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a
3407db96d56Sopenharmony_ci   text declaration (XML 1.0, section 4.3.1) using this method.
3417db96d56Sopenharmony_ci
3427db96d56Sopenharmony_ci
3437db96d56Sopenharmony_ci.. method:: ContentHandler.skippedEntity(name)
3447db96d56Sopenharmony_ci
3457db96d56Sopenharmony_ci   Receive notification of a skipped entity.
3467db96d56Sopenharmony_ci
3477db96d56Sopenharmony_ci   The Parser will invoke this method once for each entity skipped. Non-validating
3487db96d56Sopenharmony_ci   processors may skip entities if they have not seen the declarations (because,
3497db96d56Sopenharmony_ci   for example, the entity was declared in an external DTD subset). All processors
3507db96d56Sopenharmony_ci   may skip external entities, depending on the values of the
3517db96d56Sopenharmony_ci   ``feature_external_ges`` and the ``feature_external_pes`` properties.
3527db96d56Sopenharmony_ci
3537db96d56Sopenharmony_ci
3547db96d56Sopenharmony_ci.. _dtd-handler-objects:
3557db96d56Sopenharmony_ci
3567db96d56Sopenharmony_ciDTDHandler Objects
3577db96d56Sopenharmony_ci------------------
3587db96d56Sopenharmony_ci
3597db96d56Sopenharmony_ci:class:`DTDHandler` instances provide the following methods:
3607db96d56Sopenharmony_ci
3617db96d56Sopenharmony_ci
3627db96d56Sopenharmony_ci.. method:: DTDHandler.notationDecl(name, publicId, systemId)
3637db96d56Sopenharmony_ci
3647db96d56Sopenharmony_ci   Handle a notation declaration event.
3657db96d56Sopenharmony_ci
3667db96d56Sopenharmony_ci
3677db96d56Sopenharmony_ci.. method:: DTDHandler.unparsedEntityDecl(name, publicId, systemId, ndata)
3687db96d56Sopenharmony_ci
3697db96d56Sopenharmony_ci   Handle an unparsed entity declaration event.
3707db96d56Sopenharmony_ci
3717db96d56Sopenharmony_ci
3727db96d56Sopenharmony_ci.. _entity-resolver-objects:
3737db96d56Sopenharmony_ci
3747db96d56Sopenharmony_ciEntityResolver Objects
3757db96d56Sopenharmony_ci----------------------
3767db96d56Sopenharmony_ci
3777db96d56Sopenharmony_ci
3787db96d56Sopenharmony_ci.. method:: EntityResolver.resolveEntity(publicId, systemId)
3797db96d56Sopenharmony_ci
3807db96d56Sopenharmony_ci   Resolve the system identifier of an entity and return either the system
3817db96d56Sopenharmony_ci   identifier to read from as a string, or an InputSource to read from. The default
3827db96d56Sopenharmony_ci   implementation returns *systemId*.
3837db96d56Sopenharmony_ci
3847db96d56Sopenharmony_ci
3857db96d56Sopenharmony_ci.. _sax-error-handler:
3867db96d56Sopenharmony_ci
3877db96d56Sopenharmony_ciErrorHandler Objects
3887db96d56Sopenharmony_ci--------------------
3897db96d56Sopenharmony_ci
3907db96d56Sopenharmony_ciObjects with this interface are used to receive error and warning information
3917db96d56Sopenharmony_cifrom the :class:`~xml.sax.xmlreader.XMLReader`.  If you create an object that
3927db96d56Sopenharmony_ciimplements this interface, then register the object with your
3937db96d56Sopenharmony_ci:class:`~xml.sax.xmlreader.XMLReader`, the parser
3947db96d56Sopenharmony_ciwill call the methods in your object to report all warnings and errors. There
3957db96d56Sopenharmony_ciare three levels of errors available: warnings, (possibly) recoverable errors,
3967db96d56Sopenharmony_ciand unrecoverable errors.  All methods take a :exc:`SAXParseException` as the
3977db96d56Sopenharmony_cionly parameter.  Errors and warnings may be converted to an exception by raising
3987db96d56Sopenharmony_cithe passed-in exception object.
3997db96d56Sopenharmony_ci
4007db96d56Sopenharmony_ci
4017db96d56Sopenharmony_ci.. method:: ErrorHandler.error(exception)
4027db96d56Sopenharmony_ci
4037db96d56Sopenharmony_ci   Called when the parser encounters a recoverable error.  If this method does not
4047db96d56Sopenharmony_ci   raise an exception, parsing may continue, but further document information
4057db96d56Sopenharmony_ci   should not be expected by the application.  Allowing the parser to continue may
4067db96d56Sopenharmony_ci   allow additional errors to be discovered in the input document.
4077db96d56Sopenharmony_ci
4087db96d56Sopenharmony_ci
4097db96d56Sopenharmony_ci.. method:: ErrorHandler.fatalError(exception)
4107db96d56Sopenharmony_ci
4117db96d56Sopenharmony_ci   Called when the parser encounters an error it cannot recover from; parsing is
4127db96d56Sopenharmony_ci   expected to terminate when this method returns.
4137db96d56Sopenharmony_ci
4147db96d56Sopenharmony_ci
4157db96d56Sopenharmony_ci.. method:: ErrorHandler.warning(exception)
4167db96d56Sopenharmony_ci
4177db96d56Sopenharmony_ci   Called when the parser presents minor warning information to the application.
4187db96d56Sopenharmony_ci   Parsing is expected to continue when this method returns, and document
4197db96d56Sopenharmony_ci   information will continue to be passed to the application. Raising an exception
4207db96d56Sopenharmony_ci   in this method will cause parsing to end.
4217db96d56Sopenharmony_ci
4227db96d56Sopenharmony_ci
4237db96d56Sopenharmony_ci.. _lexical-handler-objects:
4247db96d56Sopenharmony_ci
4257db96d56Sopenharmony_ciLexicalHandler Objects
4267db96d56Sopenharmony_ci----------------------
4277db96d56Sopenharmony_ciOptional SAX2 handler for lexical events.
4287db96d56Sopenharmony_ci
4297db96d56Sopenharmony_ciThis handler is used to obtain lexical information about an XML
4307db96d56Sopenharmony_cidocument. Lexical information includes information describing the
4317db96d56Sopenharmony_cidocument encoding used and XML comments embedded in the document, as
4327db96d56Sopenharmony_ciwell as section boundaries for the DTD and for any CDATA sections.
4337db96d56Sopenharmony_ciThe lexical handlers are used in the same manner as content handlers.
4347db96d56Sopenharmony_ci
4357db96d56Sopenharmony_ciSet the LexicalHandler of an XMLReader by using the setProperty method
4367db96d56Sopenharmony_ciwith the property identifier
4377db96d56Sopenharmony_ci``'http://xml.org/sax/properties/lexical-handler'``.
4387db96d56Sopenharmony_ci
4397db96d56Sopenharmony_ci
4407db96d56Sopenharmony_ci.. method:: LexicalHandler.comment(content)
4417db96d56Sopenharmony_ci
4427db96d56Sopenharmony_ci   Reports a comment anywhere in the document (including the DTD and
4437db96d56Sopenharmony_ci   outside the document element).
4447db96d56Sopenharmony_ci
4457db96d56Sopenharmony_ci.. method:: LexicalHandler.startDTD(name, public_id, system_id)
4467db96d56Sopenharmony_ci
4477db96d56Sopenharmony_ci   Reports the start of the DTD declarations if the document has an
4487db96d56Sopenharmony_ci   associated DTD.
4497db96d56Sopenharmony_ci
4507db96d56Sopenharmony_ci.. method:: LexicalHandler.endDTD()
4517db96d56Sopenharmony_ci
4527db96d56Sopenharmony_ci   Reports the end of DTD declaration.
4537db96d56Sopenharmony_ci
4547db96d56Sopenharmony_ci.. method:: LexicalHandler.startCDATA()
4557db96d56Sopenharmony_ci
4567db96d56Sopenharmony_ci   Reports the start of a CDATA marked section.
4577db96d56Sopenharmony_ci
4587db96d56Sopenharmony_ci   The contents of the CDATA marked section will be reported through
4597db96d56Sopenharmony_ci   the characters handler.
4607db96d56Sopenharmony_ci
4617db96d56Sopenharmony_ci.. method:: LexicalHandler.endCDATA()
4627db96d56Sopenharmony_ci
4637db96d56Sopenharmony_ci   Reports the end of a CDATA marked section.
464