gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

809 line
58KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="xml.sax.handler — Base classes for SAX handlers" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/xml.sax.handler.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/xml/sax/handler.py The SAX API defines five kinds of handlers: content handlers, DTD handlers, error handlers, entity resolvers and lexical handlers. Applications normally only nee..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/xml/sax/handler.py The SAX API defines five kinds of handlers: content handlers, DTD handlers, error handlers, entity resolvers and lexical handlers. Applications normally only nee..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>xml.sax.handler — Base classes for SAX handlers &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="xml.sax.saxutils — SAX Utilities" href="xml.sax.utils.html" />
  33. <link rel="prev" title="xml.sax — Support for SAX2 parsers" href="xml.sax.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/xml.sax.handler.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> — Base classes for SAX handlers</a><ul>
  86. <li><a class="reference internal" href="#contenthandler-objects">ContentHandler Objects</a></li>
  87. <li><a class="reference internal" href="#dtdhandler-objects">DTDHandler Objects</a></li>
  88. <li><a class="reference internal" href="#entityresolver-objects">EntityResolver Objects</a></li>
  89. <li><a class="reference internal" href="#errorhandler-objects">ErrorHandler Objects</a></li>
  90. <li><a class="reference internal" href="#lexicalhandler-objects">LexicalHandler Objects</a></li>
  91. </ul>
  92. </li>
  93. </ul>
  94. </div>
  95. <div>
  96. <h4>Previous topic</h4>
  97. <p class="topless"><a href="xml.sax.html"
  98. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a></p>
  99. </div>
  100. <div>
  101. <h4>Next topic</h4>
  102. <p class="topless"><a href="xml.sax.utils.html"
  103. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.saxutils</span></code> — SAX Utilities</a></p>
  104. </div>
  105. <div role="note" aria-label="source link">
  106. <h3>This Page</h3>
  107. <ul class="this-page-menu">
  108. <li><a href="../bugs.html">Report a Bug</a></li>
  109. <li>
  110. <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.sax.handler.rst"
  111. rel="nofollow">Show Source
  112. </a>
  113. </li>
  114. </ul>
  115. </div>
  116. </nav>
  117. </div>
  118. </div>
  119. <div class="related" role="navigation" aria-label="related navigation">
  120. <h3>Navigation</h3>
  121. <ul>
  122. <li class="right" style="margin-right: 10px">
  123. <a href="../genindex.html" title="General Index"
  124. accesskey="I">index</a></li>
  125. <li class="right" >
  126. <a href="../py-modindex.html" title="Python Module Index"
  127. >modules</a> |</li>
  128. <li class="right" >
  129. <a href="xml.sax.utils.html" title="xml.sax.saxutils — SAX Utilities"
  130. accesskey="N">next</a> |</li>
  131. <li class="right" >
  132. <a href="xml.sax.html" title="xml.sax — Support for SAX2 parsers"
  133. accesskey="P">previous</a> |</li>
  134. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  135. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  136. <li class="switchers">
  137. <div class="language_switcher_placeholder"></div>
  138. <div class="version_switcher_placeholder"></div>
  139. </li>
  140. <li>
  141. </li>
  142. <li id="cpython-language-and-version">
  143. <a href="../index.html">3.12.3 Documentation</a> &#187;
  144. </li>
  145. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  146. <li class="nav-item nav-item-2"><a href="markup.html" accesskey="U">Structured Markup Processing Tools</a> &#187;</li>
  147. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> — Base classes for SAX handlers</a></li>
  148. <li class="right">
  149. <div class="inline-search" role="search">
  150. <form class="inline-search" action="../search.html" method="get">
  151. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  152. <input type="submit" value="Go" />
  153. </form>
  154. </div>
  155. |
  156. </li>
  157. <li class="right">
  158. <label class="theme-selector-label">
  159. Theme
  160. <select class="theme-selector" oninput="activateTheme(this.value)">
  161. <option value="auto" selected>Auto</option>
  162. <option value="light">Light</option>
  163. <option value="dark">Dark</option>
  164. </select>
  165. </label> |</li>
  166. </ul>
  167. </div>
  168. <div class="document">
  169. <div class="documentwrapper">
  170. <div class="bodywrapper">
  171. <div class="body" role="main">
  172. <section id="module-xml.sax.handler">
  173. <span id="xml-sax-handler-base-classes-for-sax-handlers"></span><h1><a class="reference internal" href="#module-xml.sax.handler" title="xml.sax.handler: Base classes for SAX event handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code></a> — Base classes for SAX handlers<a class="headerlink" href="#module-xml.sax.handler" title="Link to this heading">¶</a></h1>
  174. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/xml/sax/handler.py">Lib/xml/sax/handler.py</a></p>
  175. <hr class="docutils" />
  176. <p>The SAX API defines five kinds of handlers: content handlers, DTD handlers,
  177. error handlers, entity resolvers and lexical handlers. Applications normally
  178. only need to implement those interfaces whose events they are interested in;
  179. they can implement the interfaces in a single object or in multiple objects.
  180. Handler implementations should inherit from the base classes provided in the
  181. module <a class="reference internal" href="#module-xml.sax.handler" title="xml.sax.handler: Base classes for SAX event handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code></a>, so that all methods get default implementations.</p>
  182. <dl class="py class">
  183. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler">
  184. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">ContentHandler</span></span><a class="headerlink" href="#xml.sax.handler.ContentHandler" title="Link to this definition">¶</a></dt>
  185. <dd><p>This is the main callback interface in SAX, and the one most important to
  186. applications. The order of events in this interface mirrors the order of the
  187. information in the document.</p>
  188. </dd></dl>
  189. <dl class="py class">
  190. <dt class="sig sig-object py" id="xml.sax.handler.DTDHandler">
  191. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">DTDHandler</span></span><a class="headerlink" href="#xml.sax.handler.DTDHandler" title="Link to this definition">¶</a></dt>
  192. <dd><p>Handle DTD events.</p>
  193. <p>This interface specifies only those DTD events required for basic parsing
  194. (unparsed entities and attributes).</p>
  195. </dd></dl>
  196. <dl class="py class">
  197. <dt class="sig sig-object py" id="xml.sax.handler.EntityResolver">
  198. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">EntityResolver</span></span><a class="headerlink" href="#xml.sax.handler.EntityResolver" title="Link to this definition">¶</a></dt>
  199. <dd><p>Basic interface for resolving entities. If you create an object implementing
  200. this interface, then register the object with your Parser, the parser will call
  201. the method in your object to resolve all external entities.</p>
  202. </dd></dl>
  203. <dl class="py class">
  204. <dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler">
  205. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">ErrorHandler</span></span><a class="headerlink" href="#xml.sax.handler.ErrorHandler" title="Link to this definition">¶</a></dt>
  206. <dd><p>Interface used by the parser to present error and warning messages to the
  207. application. The methods of this object control whether errors are immediately
  208. converted to exceptions or are handled in some other way.</p>
  209. </dd></dl>
  210. <dl class="py class">
  211. <dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler">
  212. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">LexicalHandler</span></span><a class="headerlink" href="#xml.sax.handler.LexicalHandler" title="Link to this definition">¶</a></dt>
  213. <dd><p>Interface used by the parser to represent low frequency events which may not
  214. be of interest to many applications.</p>
  215. </dd></dl>
  216. <p>In addition to these classes, <a class="reference internal" href="#module-xml.sax.handler" title="xml.sax.handler: Base classes for SAX event handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code></a> provides symbolic constants
  217. for the feature and property names.</p>
  218. <dl class="py data">
  219. <dt class="sig sig-object py" id="xml.sax.handler.feature_namespaces">
  220. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">feature_namespaces</span></span><a class="headerlink" href="#xml.sax.handler.feature_namespaces" title="Link to this definition">¶</a></dt>
  221. <dd><div class="line-block">
  222. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/namespaces&quot;</span></code></div>
  223. <div class="line">true: Perform Namespace processing.</div>
  224. <div class="line">false: Optionally do not perform Namespace processing (implies
  225. namespace-prefixes; default).</div>
  226. <div class="line">access: (parsing) read-only; (not parsing) read/write</div>
  227. </div>
  228. </dd></dl>
  229. <dl class="py data">
  230. <dt class="sig sig-object py" id="xml.sax.handler.feature_namespace_prefixes">
  231. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">feature_namespace_prefixes</span></span><a class="headerlink" href="#xml.sax.handler.feature_namespace_prefixes" title="Link to this definition">¶</a></dt>
  232. <dd><div class="line-block">
  233. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/namespace-prefixes&quot;</span></code></div>
  234. <div class="line">true: Report the original prefixed names and attributes used for Namespace
  235. declarations.</div>
  236. <div class="line">false: Do not report attributes used for Namespace declarations, and
  237. optionally do not report original prefixed names (default).</div>
  238. <div class="line">access: (parsing) read-only; (not parsing) read/write</div>
  239. </div>
  240. </dd></dl>
  241. <dl class="py data">
  242. <dt class="sig sig-object py" id="xml.sax.handler.feature_string_interning">
  243. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">feature_string_interning</span></span><a class="headerlink" href="#xml.sax.handler.feature_string_interning" title="Link to this definition">¶</a></dt>
  244. <dd><div class="line-block">
  245. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/string-interning&quot;</span></code></div>
  246. <div class="line">true: All element names, prefixes, attribute names, Namespace URIs, and
  247. local names are interned using the built-in intern function.</div>
  248. <div class="line">false: Names are not necessarily interned, although they may be (default).</div>
  249. <div class="line">access: (parsing) read-only; (not parsing) read/write</div>
  250. </div>
  251. </dd></dl>
  252. <dl class="py data">
  253. <dt class="sig sig-object py" id="xml.sax.handler.feature_validation">
  254. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">feature_validation</span></span><a class="headerlink" href="#xml.sax.handler.feature_validation" title="Link to this definition">¶</a></dt>
  255. <dd><div class="line-block">
  256. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/validation&quot;</span></code></div>
  257. <div class="line">true: Report all validation errors (implies external-general-entities and
  258. external-parameter-entities).</div>
  259. <div class="line">false: Do not report validation errors.</div>
  260. <div class="line">access: (parsing) read-only; (not parsing) read/write</div>
  261. </div>
  262. </dd></dl>
  263. <dl class="py data">
  264. <dt class="sig sig-object py" id="xml.sax.handler.feature_external_ges">
  265. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">feature_external_ges</span></span><a class="headerlink" href="#xml.sax.handler.feature_external_ges" title="Link to this definition">¶</a></dt>
  266. <dd><div class="line-block">
  267. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/external-general-entities&quot;</span></code></div>
  268. <div class="line">true: Include all external general (text) entities.</div>
  269. <div class="line">false: Do not include external general entities.</div>
  270. <div class="line">access: (parsing) read-only; (not parsing) read/write</div>
  271. </div>
  272. </dd></dl>
  273. <dl class="py data">
  274. <dt class="sig sig-object py" id="xml.sax.handler.feature_external_pes">
  275. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">feature_external_pes</span></span><a class="headerlink" href="#xml.sax.handler.feature_external_pes" title="Link to this definition">¶</a></dt>
  276. <dd><div class="line-block">
  277. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/external-parameter-entities&quot;</span></code></div>
  278. <div class="line">true: Include all external parameter entities, including the external DTD
  279. subset.</div>
  280. <div class="line">false: Do not include any external parameter entities, even the external
  281. DTD subset.</div>
  282. <div class="line">access: (parsing) read-only; (not parsing) read/write</div>
  283. </div>
  284. </dd></dl>
  285. <dl class="py data">
  286. <dt class="sig sig-object py" id="xml.sax.handler.all_features">
  287. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">all_features</span></span><a class="headerlink" href="#xml.sax.handler.all_features" title="Link to this definition">¶</a></dt>
  288. <dd><p>List of all features.</p>
  289. </dd></dl>
  290. <dl class="py data">
  291. <dt class="sig sig-object py" id="xml.sax.handler.property_lexical_handler">
  292. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">property_lexical_handler</span></span><a class="headerlink" href="#xml.sax.handler.property_lexical_handler" title="Link to this definition">¶</a></dt>
  293. <dd><div class="line-block">
  294. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/lexical-handler&quot;</span></code></div>
  295. <div class="line">data type: xml.sax.handler.LexicalHandler (not supported in Python 2)</div>
  296. <div class="line">description: An optional extension handler for lexical events like
  297. comments.</div>
  298. <div class="line">access: read/write</div>
  299. </div>
  300. </dd></dl>
  301. <dl class="py data">
  302. <dt class="sig sig-object py" id="xml.sax.handler.property_declaration_handler">
  303. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">property_declaration_handler</span></span><a class="headerlink" href="#xml.sax.handler.property_declaration_handler" title="Link to this definition">¶</a></dt>
  304. <dd><div class="line-block">
  305. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/declaration-handler&quot;</span></code></div>
  306. <div class="line">data type: xml.sax.sax2lib.DeclHandler (not supported in Python 2)</div>
  307. <div class="line">description: An optional extension handler for DTD-related events other
  308. than notations and unparsed entities.</div>
  309. <div class="line">access: read/write</div>
  310. </div>
  311. </dd></dl>
  312. <dl class="py data">
  313. <dt class="sig sig-object py" id="xml.sax.handler.property_dom_node">
  314. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">property_dom_node</span></span><a class="headerlink" href="#xml.sax.handler.property_dom_node" title="Link to this definition">¶</a></dt>
  315. <dd><div class="line-block">
  316. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/dom-node&quot;</span></code></div>
  317. <div class="line">data type: org.w3c.dom.Node (not supported in Python 2)</div>
  318. <div class="line">description: When parsing, the current DOM node being visited if this is
  319. a DOM iterator; when not parsing, the root DOM node for iteration.</div>
  320. <div class="line">access: (parsing) read-only; (not parsing) read/write</div>
  321. </div>
  322. </dd></dl>
  323. <dl class="py data">
  324. <dt class="sig sig-object py" id="xml.sax.handler.property_xml_string">
  325. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">property_xml_string</span></span><a class="headerlink" href="#xml.sax.handler.property_xml_string" title="Link to this definition">¶</a></dt>
  326. <dd><div class="line-block">
  327. <div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/xml-string&quot;</span></code></div>
  328. <div class="line">data type: Bytes</div>
  329. <div class="line">description: The literal string of characters that was the source for the
  330. current event.</div>
  331. <div class="line">access: read-only</div>
  332. </div>
  333. </dd></dl>
  334. <dl class="py data">
  335. <dt class="sig sig-object py" id="xml.sax.handler.all_properties">
  336. <span class="sig-prename descclassname"><span class="pre">xml.sax.handler.</span></span><span class="sig-name descname"><span class="pre">all_properties</span></span><a class="headerlink" href="#xml.sax.handler.all_properties" title="Link to this definition">¶</a></dt>
  337. <dd><p>List of all known property names.</p>
  338. </dd></dl>
  339. <section id="contenthandler-objects">
  340. <span id="content-handler-objects"></span><h2>ContentHandler Objects<a class="headerlink" href="#contenthandler-objects" title="Link to this heading">¶</a></h2>
  341. <p>Users are expected to subclass <a class="reference internal" href="#xml.sax.handler.ContentHandler" title="xml.sax.handler.ContentHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">ContentHandler</span></code></a> to support their
  342. application. The following methods are called by the parser on the appropriate
  343. events in the input document:</p>
  344. <dl class="py method">
  345. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.setDocumentLocator">
  346. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">setDocumentLocator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">locator</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.setDocumentLocator" title="Link to this definition">¶</a></dt>
  347. <dd><p>Called by the parser to give the application a locator for locating the origin
  348. of document events.</p>
  349. <p>SAX parsers are strongly encouraged (though not absolutely required) to supply a
  350. locator: if it does so, it must supply the locator to the application by
  351. invoking this method before invoking any of the other methods in the
  352. DocumentHandler interface.</p>
  353. <p>The locator allows the application to determine the end position of any
  354. document-related event, even if the parser is not reporting an error. Typically,
  355. the application will use this information for reporting its own errors (such as
  356. character content that does not match an application’s business rules). The
  357. information returned by the locator is probably not sufficient for use with a
  358. search engine.</p>
  359. <p>Note that the locator will return correct information only during the invocation
  360. of the events in this interface. The application should not attempt to use it at
  361. any other time.</p>
  362. </dd></dl>
  363. <dl class="py method">
  364. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startDocument">
  365. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">startDocument</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.startDocument" title="Link to this definition">¶</a></dt>
  366. <dd><p>Receive notification of the beginning of a document.</p>
  367. <p>The SAX parser will invoke this method only once, before any other methods in
  368. this interface or in DTDHandler (except for <a class="reference internal" href="#xml.sax.handler.ContentHandler.setDocumentLocator" title="xml.sax.handler.ContentHandler.setDocumentLocator"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setDocumentLocator()</span></code></a>).</p>
  369. </dd></dl>
  370. <dl class="py method">
  371. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endDocument">
  372. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">endDocument</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.endDocument" title="Link to this definition">¶</a></dt>
  373. <dd><p>Receive notification of the end of a document.</p>
  374. <p>The SAX parser will invoke this method only once, and it will be the last method
  375. invoked during the parse. The parser shall not invoke this method until it has
  376. either abandoned parsing (because of an unrecoverable error) or reached the end
  377. of input.</p>
  378. </dd></dl>
  379. <dl class="py method">
  380. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startPrefixMapping">
  381. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">startPrefixMapping</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">prefix</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">uri</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.startPrefixMapping" title="Link to this definition">¶</a></dt>
  382. <dd><p>Begin the scope of a prefix-URI Namespace mapping.</p>
  383. <p>The information from this event is not necessary for normal Namespace
  384. processing: the SAX XML reader will automatically replace prefixes for element
  385. and attribute names when the <code class="docutils literal notranslate"><span class="pre">feature_namespaces</span></code> feature is enabled (the
  386. default).</p>
  387. <p>There are cases, however, when applications need to use prefixes in character
  388. data or in attribute values, where they cannot safely be expanded automatically;
  389. the <a class="reference internal" href="#xml.sax.handler.ContentHandler.startPrefixMapping" title="xml.sax.handler.ContentHandler.startPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">startPrefixMapping()</span></code></a> and <a class="reference internal" href="#xml.sax.handler.ContentHandler.endPrefixMapping" title="xml.sax.handler.ContentHandler.endPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endPrefixMapping()</span></code></a> events supply the
  390. information to the application to expand prefixes in those contexts itself, if
  391. necessary.</p>
  392. <p>Note that <a class="reference internal" href="#xml.sax.handler.ContentHandler.startPrefixMapping" title="xml.sax.handler.ContentHandler.startPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">startPrefixMapping()</span></code></a> and <a class="reference internal" href="#xml.sax.handler.ContentHandler.endPrefixMapping" title="xml.sax.handler.ContentHandler.endPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endPrefixMapping()</span></code></a> events are not
  393. guaranteed to be properly nested relative to each-other: all
  394. <a class="reference internal" href="#xml.sax.handler.ContentHandler.startPrefixMapping" title="xml.sax.handler.ContentHandler.startPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">startPrefixMapping()</span></code></a> events will occur before the corresponding
  395. <a class="reference internal" href="#xml.sax.handler.ContentHandler.startElement" title="xml.sax.handler.ContentHandler.startElement"><code class="xref py py-meth docutils literal notranslate"><span class="pre">startElement()</span></code></a> event, and all <a class="reference internal" href="#xml.sax.handler.ContentHandler.endPrefixMapping" title="xml.sax.handler.ContentHandler.endPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endPrefixMapping()</span></code></a> events will occur
  396. after the corresponding <a class="reference internal" href="#xml.sax.handler.ContentHandler.endElement" title="xml.sax.handler.ContentHandler.endElement"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endElement()</span></code></a> event, but their order is not
  397. guaranteed.</p>
  398. </dd></dl>
  399. <dl class="py method">
  400. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endPrefixMapping">
  401. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">endPrefixMapping</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">prefix</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.endPrefixMapping" title="Link to this definition">¶</a></dt>
  402. <dd><p>End the scope of a prefix-URI mapping.</p>
  403. <p>See <a class="reference internal" href="#xml.sax.handler.ContentHandler.startPrefixMapping" title="xml.sax.handler.ContentHandler.startPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">startPrefixMapping()</span></code></a> for details. This event will always occur after
  404. the corresponding <a class="reference internal" href="#xml.sax.handler.ContentHandler.endElement" title="xml.sax.handler.ContentHandler.endElement"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endElement()</span></code></a> event, but the order of
  405. <a class="reference internal" href="#xml.sax.handler.ContentHandler.endPrefixMapping" title="xml.sax.handler.ContentHandler.endPrefixMapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endPrefixMapping()</span></code></a> events is not otherwise guaranteed.</p>
  406. </dd></dl>
  407. <dl class="py method">
  408. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startElement">
  409. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">startElement</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attrs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.startElement" title="Link to this definition">¶</a></dt>
  410. <dd><p>Signals the start of an element in non-namespace mode.</p>
  411. <p>The <em>name</em> parameter contains the raw XML 1.0 name of the element type as a
  412. string and the <em>attrs</em> parameter holds an object of the
  413. <code class="xref py py-class docutils literal notranslate"><span class="pre">Attributes</span></code>
  414. interface (see <a class="reference internal" href="xml.sax.reader.html#attributes-objects"><span class="std std-ref">The Attributes Interface</span></a>) containing the attributes of
  415. the element. The object passed as <em>attrs</em> may be re-used by the parser; holding
  416. on to a reference to it is not a reliable way to keep a copy of the attributes.
  417. To keep a copy of the attributes, use the <a class="reference internal" href="copy.html#module-copy" title="copy: Shallow and deep copy operations."><code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code></a> method of the <em>attrs</em>
  418. object.</p>
  419. </dd></dl>
  420. <dl class="py method">
  421. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endElement">
  422. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">endElement</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.endElement" title="Link to this definition">¶</a></dt>
  423. <dd><p>Signals the end of an element in non-namespace mode.</p>
  424. <p>The <em>name</em> parameter contains the name of the element type, just as with the
  425. <a class="reference internal" href="#xml.sax.handler.ContentHandler.startElement" title="xml.sax.handler.ContentHandler.startElement"><code class="xref py py-meth docutils literal notranslate"><span class="pre">startElement()</span></code></a> event.</p>
  426. </dd></dl>
  427. <dl class="py method">
  428. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startElementNS">
  429. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">startElementNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">qname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attrs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.startElementNS" title="Link to this definition">¶</a></dt>
  430. <dd><p>Signals the start of an element in namespace mode.</p>
  431. <p>The <em>name</em> parameter contains the name of the element type as a <code class="docutils literal notranslate"><span class="pre">(uri,</span>
  432. <span class="pre">localname)</span></code> tuple, the <em>qname</em> parameter contains the raw XML 1.0 name used in
  433. the source document, and the <em>attrs</em> parameter holds an instance of the
  434. <code class="xref py py-class docutils literal notranslate"><span class="pre">AttributesNS</span></code> interface (see
  435. <a class="reference internal" href="xml.sax.reader.html#attributes-ns-objects"><span class="std std-ref">The AttributesNS Interface</span></a>)
  436. containing the attributes of the element. If no namespace is associated with
  437. the element, the <em>uri</em> component of <em>name</em> will be <code class="docutils literal notranslate"><span class="pre">None</span></code>. The object passed
  438. as <em>attrs</em> may be re-used by the parser; holding on to a reference to it is not
  439. a reliable way to keep a copy of the attributes. To keep a copy of the
  440. attributes, use the <a class="reference internal" href="copy.html#module-copy" title="copy: Shallow and deep copy operations."><code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code></a> method of the <em>attrs</em> object.</p>
  441. <p>Parsers may set the <em>qname</em> parameter to <code class="docutils literal notranslate"><span class="pre">None</span></code>, unless the
  442. <code class="docutils literal notranslate"><span class="pre">feature_namespace_prefixes</span></code> feature is activated.</p>
  443. </dd></dl>
  444. <dl class="py method">
  445. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endElementNS">
  446. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">endElementNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">qname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.endElementNS" title="Link to this definition">¶</a></dt>
  447. <dd><p>Signals the end of an element in namespace mode.</p>
  448. <p>The <em>name</em> parameter contains the name of the element type, just as with the
  449. <a class="reference internal" href="#xml.sax.handler.ContentHandler.startElementNS" title="xml.sax.handler.ContentHandler.startElementNS"><code class="xref py py-meth docutils literal notranslate"><span class="pre">startElementNS()</span></code></a> method, likewise the <em>qname</em> parameter.</p>
  450. </dd></dl>
  451. <dl class="py method">
  452. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.characters">
  453. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">characters</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">content</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.characters" title="Link to this definition">¶</a></dt>
  454. <dd><p>Receive notification of character data.</p>
  455. <p>The Parser will call this method to report each chunk of character data. SAX
  456. parsers may return all contiguous character data in a single chunk, or they may
  457. split it into several chunks; however, all of the characters in any single event
  458. must come from the same external entity so that the Locator provides useful
  459. information.</p>
  460. <p><em>content</em> may be a string or bytes instance; the <code class="docutils literal notranslate"><span class="pre">expat</span></code> reader module
  461. always produces strings.</p>
  462. <div class="admonition note">
  463. <p class="admonition-title">Note</p>
  464. <p>The earlier SAX 1 interface provided by the Python XML Special Interest Group
  465. used a more Java-like interface for this method. Since most parsers used from
  466. Python did not take advantage of the older interface, the simpler signature was
  467. chosen to replace it. To convert old code to the new interface, use <em>content</em>
  468. instead of slicing content with the old <em>offset</em> and <em>length</em> parameters.</p>
  469. </div>
  470. </dd></dl>
  471. <dl class="py method">
  472. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.ignorableWhitespace">
  473. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">ignorableWhitespace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">whitespace</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.ignorableWhitespace" title="Link to this definition">¶</a></dt>
  474. <dd><p>Receive notification of ignorable whitespace in element content.</p>
  475. <p>Validating Parsers must use this method to report each chunk of ignorable
  476. whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating
  477. parsers may also use this method if they are capable of parsing and using
  478. content models.</p>
  479. <p>SAX parsers may return all contiguous whitespace in a single chunk, or they may
  480. split it into several chunks; however, all of the characters in any single event
  481. must come from the same external entity, so that the Locator provides useful
  482. information.</p>
  483. </dd></dl>
  484. <dl class="py method">
  485. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.processingInstruction">
  486. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">processingInstruction</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">target</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.processingInstruction" title="Link to this definition">¶</a></dt>
  487. <dd><p>Receive notification of a processing instruction.</p>
  488. <p>The Parser will invoke this method once for each processing instruction found:
  489. note that processing instructions may occur before or after the main document
  490. element.</p>
  491. <p>A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a
  492. text declaration (XML 1.0, section 4.3.1) using this method.</p>
  493. </dd></dl>
  494. <dl class="py method">
  495. <dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.skippedEntity">
  496. <span class="sig-prename descclassname"><span class="pre">ContentHandler.</span></span><span class="sig-name descname"><span class="pre">skippedEntity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ContentHandler.skippedEntity" title="Link to this definition">¶</a></dt>
  497. <dd><p>Receive notification of a skipped entity.</p>
  498. <p>The Parser will invoke this method once for each entity skipped. Non-validating
  499. processors may skip entities if they have not seen the declarations (because,
  500. for example, the entity was declared in an external DTD subset). All processors
  501. may skip external entities, depending on the values of the
  502. <code class="docutils literal notranslate"><span class="pre">feature_external_ges</span></code> and the <code class="docutils literal notranslate"><span class="pre">feature_external_pes</span></code> properties.</p>
  503. </dd></dl>
  504. </section>
  505. <section id="dtdhandler-objects">
  506. <span id="dtd-handler-objects"></span><h2>DTDHandler Objects<a class="headerlink" href="#dtdhandler-objects" title="Link to this heading">¶</a></h2>
  507. <p><a class="reference internal" href="#xml.sax.handler.DTDHandler" title="xml.sax.handler.DTDHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">DTDHandler</span></code></a> instances provide the following methods:</p>
  508. <dl class="py method">
  509. <dt class="sig sig-object py" id="xml.sax.handler.DTDHandler.notationDecl">
  510. <span class="sig-prename descclassname"><span class="pre">DTDHandler.</span></span><span class="sig-name descname"><span class="pre">notationDecl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">publicId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">systemId</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.DTDHandler.notationDecl" title="Link to this definition">¶</a></dt>
  511. <dd><p>Handle a notation declaration event.</p>
  512. </dd></dl>
  513. <dl class="py method">
  514. <dt class="sig sig-object py" id="xml.sax.handler.DTDHandler.unparsedEntityDecl">
  515. <span class="sig-prename descclassname"><span class="pre">DTDHandler.</span></span><span class="sig-name descname"><span class="pre">unparsedEntityDecl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">publicId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">systemId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ndata</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.DTDHandler.unparsedEntityDecl" title="Link to this definition">¶</a></dt>
  516. <dd><p>Handle an unparsed entity declaration event.</p>
  517. </dd></dl>
  518. </section>
  519. <section id="entityresolver-objects">
  520. <span id="entity-resolver-objects"></span><h2>EntityResolver Objects<a class="headerlink" href="#entityresolver-objects" title="Link to this heading">¶</a></h2>
  521. <dl class="py method">
  522. <dt class="sig sig-object py" id="xml.sax.handler.EntityResolver.resolveEntity">
  523. <span class="sig-prename descclassname"><span class="pre">EntityResolver.</span></span><span class="sig-name descname"><span class="pre">resolveEntity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">publicId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">systemId</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.EntityResolver.resolveEntity" title="Link to this definition">¶</a></dt>
  524. <dd><p>Resolve the system identifier of an entity and return either the system
  525. identifier to read from as a string, or an InputSource to read from. The default
  526. implementation returns <em>systemId</em>.</p>
  527. </dd></dl>
  528. </section>
  529. <section id="errorhandler-objects">
  530. <span id="sax-error-handler"></span><h2>ErrorHandler Objects<a class="headerlink" href="#errorhandler-objects" title="Link to this heading">¶</a></h2>
  531. <p>Objects with this interface are used to receive error and warning information
  532. from the <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader" title="xml.sax.xmlreader.XMLReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code></a>. If you create an object that
  533. implements this interface, then register the object with your
  534. <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader" title="xml.sax.xmlreader.XMLReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code></a>, the parser
  535. will call the methods in your object to report all warnings and errors. There
  536. are three levels of errors available: warnings, (possibly) recoverable errors,
  537. and unrecoverable errors. All methods take a <a class="reference internal" href="xml.sax.html#xml.sax.SAXParseException" title="xml.sax.SAXParseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SAXParseException</span></code></a> as the
  538. only parameter. Errors and warnings may be converted to an exception by raising
  539. the passed-in exception object.</p>
  540. <dl class="py method">
  541. <dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler.error">
  542. <span class="sig-prename descclassname"><span class="pre">ErrorHandler.</span></span><span class="sig-name descname"><span class="pre">error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exception</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ErrorHandler.error" title="Link to this definition">¶</a></dt>
  543. <dd><p>Called when the parser encounters a recoverable error. If this method does not
  544. raise an exception, parsing may continue, but further document information
  545. should not be expected by the application. Allowing the parser to continue may
  546. allow additional errors to be discovered in the input document.</p>
  547. </dd></dl>
  548. <dl class="py method">
  549. <dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler.fatalError">
  550. <span class="sig-prename descclassname"><span class="pre">ErrorHandler.</span></span><span class="sig-name descname"><span class="pre">fatalError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exception</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ErrorHandler.fatalError" title="Link to this definition">¶</a></dt>
  551. <dd><p>Called when the parser encounters an error it cannot recover from; parsing is
  552. expected to terminate when this method returns.</p>
  553. </dd></dl>
  554. <dl class="py method">
  555. <dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler.warning">
  556. <span class="sig-prename descclassname"><span class="pre">ErrorHandler.</span></span><span class="sig-name descname"><span class="pre">warning</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exception</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.ErrorHandler.warning" title="Link to this definition">¶</a></dt>
  557. <dd><p>Called when the parser presents minor warning information to the application.
  558. Parsing is expected to continue when this method returns, and document
  559. information will continue to be passed to the application. Raising an exception
  560. in this method will cause parsing to end.</p>
  561. </dd></dl>
  562. </section>
  563. <section id="lexicalhandler-objects">
  564. <span id="lexical-handler-objects"></span><h2>LexicalHandler Objects<a class="headerlink" href="#lexicalhandler-objects" title="Link to this heading">¶</a></h2>
  565. <p>Optional SAX2 handler for lexical events.</p>
  566. <p>This handler is used to obtain lexical information about an XML
  567. document. Lexical information includes information describing the
  568. document encoding used and XML comments embedded in the document, as
  569. well as section boundaries for the DTD and for any CDATA sections.
  570. The lexical handlers are used in the same manner as content handlers.</p>
  571. <p>Set the LexicalHandler of an XMLReader by using the setProperty method
  572. with the property identifier
  573. <code class="docutils literal notranslate"><span class="pre">'http://xml.org/sax/properties/lexical-handler'</span></code>.</p>
  574. <dl class="py method">
  575. <dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.comment">
  576. <span class="sig-prename descclassname"><span class="pre">LexicalHandler.</span></span><span class="sig-name descname"><span class="pre">comment</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">content</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.LexicalHandler.comment" title="Link to this definition">¶</a></dt>
  577. <dd><p>Reports a comment anywhere in the document (including the DTD and
  578. outside the document element).</p>
  579. </dd></dl>
  580. <dl class="py method">
  581. <dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.startDTD">
  582. <span class="sig-prename descclassname"><span class="pre">LexicalHandler.</span></span><span class="sig-name descname"><span class="pre">startDTD</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">public_id</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">system_id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.LexicalHandler.startDTD" title="Link to this definition">¶</a></dt>
  583. <dd><p>Reports the start of the DTD declarations if the document has an
  584. associated DTD.</p>
  585. </dd></dl>
  586. <dl class="py method">
  587. <dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.endDTD">
  588. <span class="sig-prename descclassname"><span class="pre">LexicalHandler.</span></span><span class="sig-name descname"><span class="pre">endDTD</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.LexicalHandler.endDTD" title="Link to this definition">¶</a></dt>
  589. <dd><p>Reports the end of DTD declaration.</p>
  590. </dd></dl>
  591. <dl class="py method">
  592. <dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.startCDATA">
  593. <span class="sig-prename descclassname"><span class="pre">LexicalHandler.</span></span><span class="sig-name descname"><span class="pre">startCDATA</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.LexicalHandler.startCDATA" title="Link to this definition">¶</a></dt>
  594. <dd><p>Reports the start of a CDATA marked section.</p>
  595. <p>The contents of the CDATA marked section will be reported through
  596. the characters handler.</p>
  597. </dd></dl>
  598. <dl class="py method">
  599. <dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.endCDATA">
  600. <span class="sig-prename descclassname"><span class="pre">LexicalHandler.</span></span><span class="sig-name descname"><span class="pre">endCDATA</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.handler.LexicalHandler.endCDATA" title="Link to this definition">¶</a></dt>
  601. <dd><p>Reports the end of a CDATA marked section.</p>
  602. </dd></dl>
  603. </section>
  604. </section>
  605. <div class="clearer"></div>
  606. </div>
  607. </div>
  608. </div>
  609. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  610. <div class="sphinxsidebarwrapper">
  611. <div>
  612. <h3><a href="../contents.html">Table of Contents</a></h3>
  613. <ul>
  614. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> — Base classes for SAX handlers</a><ul>
  615. <li><a class="reference internal" href="#contenthandler-objects">ContentHandler Objects</a></li>
  616. <li><a class="reference internal" href="#dtdhandler-objects">DTDHandler Objects</a></li>
  617. <li><a class="reference internal" href="#entityresolver-objects">EntityResolver Objects</a></li>
  618. <li><a class="reference internal" href="#errorhandler-objects">ErrorHandler Objects</a></li>
  619. <li><a class="reference internal" href="#lexicalhandler-objects">LexicalHandler Objects</a></li>
  620. </ul>
  621. </li>
  622. </ul>
  623. </div>
  624. <div>
  625. <h4>Previous topic</h4>
  626. <p class="topless"><a href="xml.sax.html"
  627. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a></p>
  628. </div>
  629. <div>
  630. <h4>Next topic</h4>
  631. <p class="topless"><a href="xml.sax.utils.html"
  632. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.saxutils</span></code> — SAX Utilities</a></p>
  633. </div>
  634. <div role="note" aria-label="source link">
  635. <h3>This Page</h3>
  636. <ul class="this-page-menu">
  637. <li><a href="../bugs.html">Report a Bug</a></li>
  638. <li>
  639. <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.sax.handler.rst"
  640. rel="nofollow">Show Source
  641. </a>
  642. </li>
  643. </ul>
  644. </div>
  645. </div>
  646. <div id="sidebarbutton" title="Collapse sidebar">
  647. <span>«</span>
  648. </div>
  649. </div>
  650. <div class="clearer"></div>
  651. </div>
  652. <div class="related" role="navigation" aria-label="related navigation">
  653. <h3>Navigation</h3>
  654. <ul>
  655. <li class="right" style="margin-right: 10px">
  656. <a href="../genindex.html" title="General Index"
  657. >index</a></li>
  658. <li class="right" >
  659. <a href="../py-modindex.html" title="Python Module Index"
  660. >modules</a> |</li>
  661. <li class="right" >
  662. <a href="xml.sax.utils.html" title="xml.sax.saxutils — SAX Utilities"
  663. >next</a> |</li>
  664. <li class="right" >
  665. <a href="xml.sax.html" title="xml.sax — Support for SAX2 parsers"
  666. >previous</a> |</li>
  667. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  668. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  669. <li class="switchers">
  670. <div class="language_switcher_placeholder"></div>
  671. <div class="version_switcher_placeholder"></div>
  672. </li>
  673. <li>
  674. </li>
  675. <li id="cpython-language-and-version">
  676. <a href="../index.html">3.12.3 Documentation</a> &#187;
  677. </li>
  678. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  679. <li class="nav-item nav-item-2"><a href="markup.html" >Structured Markup Processing Tools</a> &#187;</li>
  680. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> — Base classes for SAX handlers</a></li>
  681. <li class="right">
  682. <div class="inline-search" role="search">
  683. <form class="inline-search" action="../search.html" method="get">
  684. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  685. <input type="submit" value="Go" />
  686. </form>
  687. </div>
  688. |
  689. </li>
  690. <li class="right">
  691. <label class="theme-selector-label">
  692. Theme
  693. <select class="theme-selector" oninput="activateTheme(this.value)">
  694. <option value="auto" selected>Auto</option>
  695. <option value="light">Light</option>
  696. <option value="dark">Dark</option>
  697. </select>
  698. </label> |</li>
  699. </ul>
  700. </div>
  701. <div class="footer">
  702. &copy;
  703. <a href="../copyright.html">
  704. Copyright
  705. </a>
  706. 2001-2024, Python Software Foundation.
  707. <br />
  708. This page is licensed under the Python Software Foundation License Version 2.
  709. <br />
  710. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  711. <br />
  712. See <a href="/license.html">History and License</a> for more information.<br />
  713. <br />
  714. The Python Software Foundation is a non-profit corporation.
  715. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  716. <br />
  717. <br />
  718. Last updated on Apr 09, 2024 (13:47 UTC).
  719. <a href="/bugs.html">Found a bug</a>?
  720. <br />
  721. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  722. </div>
  723. </body>
  724. </html>
上海开阖软件有限公司 沪ICP备12045867号-1