Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
xml.sax.handler.html850 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="xml.sax.handler — Base classes for SAX handlers" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/xml.sax.handler.html" />10<meta property="og:site_name" content="Python documentation" />11<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..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_xml.sax.handler_b2458d80.png" />15<meta property="og:image:alt" 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..." />16<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..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>xml.sax.handler — Base classes for SAX handlers &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="xml.sax.saxutils — SAX Utilities" href="xml.sax.utils.html" />43    <link rel="prev" title="xml.sax — Support for SAX2 parsers" href="xml.sax.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/xml.sax.handler.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <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>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<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>108<li><a class="reference internal" href="#contenthandler-objects">ContentHandler Objects</a></li>109<li><a class="reference internal" href="#dtdhandler-objects">DTDHandler Objects</a></li>110<li><a class="reference internal" href="#entityresolver-objects">EntityResolver Objects</a></li>111<li><a class="reference internal" href="#errorhandler-objects">ErrorHandler Objects</a></li>112<li><a class="reference internal" href="#lexicalhandler-objects">LexicalHandler Objects</a></li>113</ul>114</li>115</ul>116 117  </div>118  <div>119    <h4>Previous topic</h4>120    <p class="topless"><a href="xml.sax.html"121                          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>122  </div>123  <div>124    <h4>Next topic</h4>125    <p class="topless"><a href="xml.sax.utils.html"126                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.saxutils</span></code> — SAX Utilities</a></p>127  </div>128  <script>129    document.addEventListener('DOMContentLoaded', () => {130        const title = document.querySelector('meta[property="og:title"]').content;131        const elements = document.querySelectorAll('.improvepage');132        const pageurl = window.location.href.split('?')[0];133        elements.forEach(element => {134            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));135            url.searchParams.set('pagetitle', title);136            url.searchParams.set('pageurl', pageurl);137            url.searchParams.set('pagesource', "library/xml.sax.handler.rst");138            element.href = url.toString();139        });140    });141  </script>142  <div role="note" aria-label="source link">143    <h3>This page</h3>144    <ul class="this-page-menu">145      <li><a href="../bugs.html">Report a bug</a></li>146      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>147      <li>148        <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.sax.handler.rst?plain=1"149            rel="nofollow">Show source150        </a>151      </li>152      153    </ul>154  </div>155        </nav>156    </div>157</div>158 159  160    <div class="related" role="navigation" aria-label="Related">161      <h3>Navigation</h3>162      <ul>163        <li class="right" style="margin-right: 10px">164          <a href="../genindex.html" title="General Index"165             accesskey="I">index</a></li>166        <li class="right" >167          <a href="../py-modindex.html" title="Python Module Index"168             >modules</a> |</li>169        <li class="right" >170          <a href="xml.sax.utils.html" title="xml.sax.saxutils — SAX Utilities"171             accesskey="N">next</a> |</li>172        <li class="right" >173          <a href="xml.sax.html" title="xml.sax — Support for SAX2 parsers"174             accesskey="P">previous</a> |</li>175 176          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>177          <li><a href="https://www.python.org/">Python</a> &#187;</li>178          <li class="switchers">179            <div class="language_switcher_placeholder"></div>180            <div class="version_switcher_placeholder"></div>181          </li>182          <li>183              184          </li>185    <li id="cpython-language-and-version">186      <a href="../index.html">3.15.0a6 Documentation</a> &#187;187    </li>188 189          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>190          <li class="nav-item nav-item-2"><a href="markup.html" accesskey="U">Structured Markup Processing Tools</a> &#187;</li>191        <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>192                <li class="right">193                    194 195    <div class="inline-search" role="search">196        <form class="inline-search" action="../search.html" method="get">197          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">198          <input type="submit" value="Go">199        </form>200    </div>201                     |202                </li>203            <li class="right">204<label class="theme-selector-label">205    Theme206    <select class="theme-selector" oninput="activateTheme(this.value)">207        <option value="auto" selected>Auto</option>208        <option value="light">Light</option>209        <option value="dark">Dark</option>210    </select>211</label> |</li>212            213      </ul>214    </div>    215 216    <div class="document">217      <div class="documentwrapper">218        <div class="bodywrapper">219          <div class="body" role="main">220            221  <section id="module-xml.sax.handler">222<span id="xml-sax-handler-base-classes-for-sax-handlers"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> — Base classes for SAX handlers<a class="headerlink" href="#module-xml.sax.handler" title="Link to this heading">¶</a></h1>223<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/xml/sax/handler.py">Lib/xml/sax/handler.py</a></p>224<hr class="docutils" />225<p>The SAX API defines five kinds of handlers: content handlers, DTD handlers,226error handlers, entity resolvers and lexical handlers. Applications normally227only need to implement those interfaces whose events they are interested in;228they can implement the interfaces in a single object or in multiple objects.229Handler implementations should inherit from the base classes provided in the230module <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code>, so that all methods get default implementations.</p>231<dl class="py class">232<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler">233<em class="property"><span class="k"><span class="pre">class</span></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>234<dd><p>This is the main callback interface in SAX, and the one most important to235applications. The order of events in this interface mirrors the order of the236information in the document.</p>237</dd></dl>238 239<dl class="py class">240<dt class="sig sig-object py" id="xml.sax.handler.DTDHandler">241<em class="property"><span class="k"><span class="pre">class</span></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>242<dd><p>Handle DTD events.</p>243<p>This interface specifies only those DTD events required for basic parsing244(unparsed entities and attributes).</p>245</dd></dl>246 247<dl class="py class">248<dt class="sig sig-object py" id="xml.sax.handler.EntityResolver">249<em class="property"><span class="k"><span class="pre">class</span></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>250<dd><p>Basic interface for resolving entities. If you create an object implementing251this interface, then register the object with your Parser, the parser will call252the method in your object to resolve all external entities.</p>253</dd></dl>254 255<dl class="py class">256<dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler">257<em class="property"><span class="k"><span class="pre">class</span></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>258<dd><p>Interface used by the parser to present error and warning messages to the259application.  The methods of this object control whether errors are immediately260converted to exceptions or are handled in some other way.</p>261</dd></dl>262 263<dl class="py class">264<dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler">265<em class="property"><span class="k"><span class="pre">class</span></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>266<dd><p>Interface used by the parser to represent low frequency events which may not267be of interest to many applications.</p>268</dd></dl>269 270<p>In addition to these classes, <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> provides symbolic constants271for the feature and property names.</p>272<dl class="py data">273<dt class="sig sig-object py" id="xml.sax.handler.feature_namespaces">274<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>275<dd><div class="line-block">276<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/namespaces&quot;</span></code></div>277<div class="line">true: Perform Namespace processing.</div>278<div class="line">false: Optionally do not perform Namespace processing (implies279namespace-prefixes; default).</div>280<div class="line">access: (parsing) read-only; (not parsing) read/write</div>281</div>282</dd></dl>283 284<dl class="py data">285<dt class="sig sig-object py" id="xml.sax.handler.feature_namespace_prefixes">286<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>287<dd><div class="line-block">288<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/namespace-prefixes&quot;</span></code></div>289<div class="line">true: Report the original prefixed names and attributes used for Namespace290declarations.</div>291<div class="line">false: Do not report attributes used for Namespace declarations, and292optionally do not report original prefixed names (default).</div>293<div class="line">access: (parsing) read-only; (not parsing) read/write</div>294</div>295</dd></dl>296 297<dl class="py data">298<dt class="sig sig-object py" id="xml.sax.handler.feature_string_interning">299<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>300<dd><div class="line-block">301<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/string-interning&quot;</span></code></div>302<div class="line">true: All element names, prefixes, attribute names, Namespace URIs, and303local names are interned using the built-in intern function.</div>304<div class="line">false: Names are not necessarily interned, although they may be (default).</div>305<div class="line">access: (parsing) read-only; (not parsing) read/write</div>306</div>307</dd></dl>308 309<dl class="py data">310<dt class="sig sig-object py" id="xml.sax.handler.feature_validation">311<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>312<dd><div class="line-block">313<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/features/validation&quot;</span></code></div>314<div class="line">true: Report all validation errors (implies external-general-entities and315external-parameter-entities).</div>316<div class="line">false: Do not report validation errors.</div>317<div class="line">access: (parsing) read-only; (not parsing) read/write</div>318</div>319</dd></dl>320 321<dl class="py data">322<dt class="sig sig-object py" id="xml.sax.handler.feature_external_ges">323<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>324<dd><div class="admonition warning">325<p class="admonition-title">Warning</p>326<p>Enabling opens a vulnerability to327<a class="reference external" href="https://en.wikipedia.org/wiki/XML_external_entity_attack">external entity attacks</a>328if the parser is used with user-provided XML content.329Please reflect on your <a class="reference external" href="https://en.wikipedia.org/wiki/Threat_model">threat model</a>330before enabling this feature.</p>331</div>332<div class="line-block">333<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>334<div class="line">true: Include all external general (text) entities.</div>335<div class="line">false: Do not include external general entities.</div>336<div class="line">access: (parsing) read-only; (not parsing) read/write</div>337</div>338</dd></dl>339 340<dl class="py data">341<dt class="sig sig-object py" id="xml.sax.handler.feature_external_pes">342<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>343<dd><div class="line-block">344<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>345<div class="line">true: Include all external parameter entities, including the external DTD346subset.</div>347<div class="line">false: Do not include any external parameter entities, even the external348DTD subset.</div>349<div class="line">access: (parsing) read-only; (not parsing) read/write</div>350</div>351</dd></dl>352 353<dl class="py data">354<dt class="sig sig-object py" id="xml.sax.handler.all_features">355<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>356<dd><p>List of all features.</p>357</dd></dl>358 359<dl class="py data">360<dt class="sig sig-object py" id="xml.sax.handler.property_lexical_handler">361<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>362<dd><div class="line-block">363<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/lexical-handler&quot;</span></code></div>364<div class="line">data type: xml.sax.handler.LexicalHandler (not supported in Python 2)</div>365<div class="line">description: An optional extension handler for lexical events like366comments.</div>367<div class="line">access: read/write</div>368</div>369</dd></dl>370 371<dl class="py data">372<dt class="sig sig-object py" id="xml.sax.handler.property_declaration_handler">373<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>374<dd><div class="line-block">375<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/declaration-handler&quot;</span></code></div>376<div class="line">data type: xml.sax.sax2lib.DeclHandler (not supported in Python 2)</div>377<div class="line">description: An optional extension handler for DTD-related events other378than notations and unparsed entities.</div>379<div class="line">access: read/write</div>380</div>381</dd></dl>382 383<dl class="py data">384<dt class="sig sig-object py" id="xml.sax.handler.property_dom_node">385<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>386<dd><div class="line-block">387<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/dom-node&quot;</span></code></div>388<div class="line">data type: org.w3c.dom.Node (not supported in Python 2)</div>389<div class="line">description: When parsing, the current DOM node being visited if this is390a DOM iterator; when not parsing, the root DOM node for iteration.</div>391<div class="line">access: (parsing) read-only; (not parsing) read/write</div>392</div>393</dd></dl>394 395<dl class="py data">396<dt class="sig sig-object py" id="xml.sax.handler.property_xml_string">397<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>398<dd><div class="line-block">399<div class="line">value: <code class="docutils literal notranslate"><span class="pre">&quot;http://xml.org/sax/properties/xml-string&quot;</span></code></div>400<div class="line">data type: Bytes</div>401<div class="line">description: The literal string of characters that was the source for the402current event.</div>403<div class="line">access: read-only</div>404</div>405</dd></dl>406 407<dl class="py data">408<dt class="sig sig-object py" id="xml.sax.handler.all_properties">409<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>410<dd><p>List of all known property names.</p>411</dd></dl>412 413<section id="contenthandler-objects">414<span id="content-handler-objects"></span><h2>ContentHandler Objects<a class="headerlink" href="#contenthandler-objects" title="Link to this heading">¶</a></h2>415<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 their416application.  The following methods are called by the parser on the appropriate417events in the input document:</p>418<dl class="py method">419<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.setDocumentLocator">420<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>421<dd><p>Called by the parser to give the application a locator for locating the origin422of document events.</p>423<p>SAX parsers are strongly encouraged (though not absolutely required) to supply a424locator: if it does so, it must supply the locator to the application by425invoking this method before invoking any of the other methods in the426DocumentHandler interface.</p>427<p>The locator allows the application to determine the end position of any428document-related event, even if the parser is not reporting an error. Typically,429the application will use this information for reporting its own errors (such as430character content that does not match an application’s business rules). The431information returned by the locator is probably not sufficient for use with a432search engine.</p>433<p>Note that the locator will return correct information only during the invocation434of the events in this interface. The application should not attempt to use it at435any other time.</p>436</dd></dl>437 438<dl class="py method">439<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startDocument">440<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>441<dd><p>Receive notification of the beginning of a document.</p>442<p>The SAX parser will invoke this method only once, before any other methods in443this 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>444</dd></dl>445 446<dl class="py method">447<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endDocument">448<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>449<dd><p>Receive notification of the end of a document.</p>450<p>The SAX parser will invoke this method only once, and it will be the last method451invoked during the parse. The parser shall not invoke this method until it has452either abandoned parsing (because of an unrecoverable error) or reached the end453of input.</p>454</dd></dl>455 456<dl class="py method">457<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startPrefixMapping">458<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>459<dd><p>Begin the scope of a prefix-URI Namespace mapping.</p>460<p>The information from this event is not necessary for normal Namespace461processing: the SAX XML reader will automatically replace prefixes for element462and attribute names when the <code class="docutils literal notranslate"><span class="pre">feature_namespaces</span></code> feature is enabled (the463default).</p>464<p>There are cases, however, when applications need to use prefixes in character465data or in attribute values, where they cannot safely be expanded automatically;466the <code class="xref py py-meth docutils literal notranslate"><span class="pre">startPrefixMapping()</span></code> 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 the467information to the application to expand prefixes in those contexts itself, if468necessary.</p>469<p>Note that <code class="xref py py-meth docutils literal notranslate"><span class="pre">startPrefixMapping()</span></code> 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 not470guaranteed to be properly nested relative to each-other: all471<code class="xref py py-meth docutils literal notranslate"><span class="pre">startPrefixMapping()</span></code> events will occur before the corresponding472<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 <code class="xref py py-meth docutils literal notranslate"><span class="pre">endPrefixMapping()</span></code> events will occur473after 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 not474guaranteed.</p>475</dd></dl>476 477<dl class="py method">478<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endPrefixMapping">479<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>480<dd><p>End the scope of a prefix-URI mapping.</p>481<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 after482the 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 of483<code class="xref py py-meth docutils literal notranslate"><span class="pre">endPrefixMapping()</span></code> events is not otherwise guaranteed.</p>484</dd></dl>485 486<dl class="py method">487<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startElement">488<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>489<dd><p>Signals the start of an element in non-namespace mode.</p>490<p>The <em>name</em> parameter contains the raw XML 1.0 name of the element type as a491string and the <em>attrs</em> parameter holds an object of the492<a class="reference internal" href="xml.sax.reader.html#attributes-objects"><span class="std std-ref">Attributes</span></a> interface containing the attributes of493the element.  The object passed as <em>attrs</em> may be re-used by the parser; holding494on to a reference to it is not a reliable way to keep a copy of the attributes.495To 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>496object.</p>497</dd></dl>498 499<dl class="py method">500<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endElement">501<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>502<dd><p>Signals the end of an element in non-namespace mode.</p>503<p>The <em>name</em> parameter contains the name of the element type, just as with the504<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>505</dd></dl>506 507<dl class="py method">508<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.startElementNS">509<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>510<dd><p>Signals the start of an element in namespace mode.</p>511<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>512<span class="pre">localname)</span></code> tuple, the <em>qname</em> parameter contains the raw XML 1.0 name used in513the source document, and the <em>attrs</em> parameter holds an instance of the514<a class="reference internal" href="xml.sax.reader.html#attributes-ns-objects"><span class="std std-ref">AttributesNS</span></a> interface515containing the attributes of the element.  If no namespace is associated with516the 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 passed517as <em>attrs</em> may be re-used by the parser; holding on to a reference to it is not518a reliable way to keep a copy of the attributes.  To keep a copy of the519attributes, 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>520<p>Parsers may set the <em>qname</em> parameter to <code class="docutils literal notranslate"><span class="pre">None</span></code>, unless the521<code class="docutils literal notranslate"><span class="pre">feature_namespace_prefixes</span></code> feature is activated.</p>522</dd></dl>523 524<dl class="py method">525<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.endElementNS">526<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>527<dd><p>Signals the end of an element in namespace mode.</p>528<p>The <em>name</em> parameter contains the name of the element type, just as with the529<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>530</dd></dl>531 532<dl class="py method">533<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.characters">534<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>535<dd><p>Receive notification of character data.</p>536<p>The Parser will call this method to report each chunk of character data. SAX537parsers may return all contiguous character data in a single chunk, or they may538split it into several chunks; however, all of the characters in any single event539must come from the same external entity so that the Locator provides useful540information.</p>541<p><em>content</em> may be a string or bytes instance; the <code class="docutils literal notranslate"><span class="pre">expat</span></code> reader module542always produces strings.</p>543<div class="admonition note">544<p class="admonition-title">Note</p>545<p>The earlier SAX 1 interface provided by the Python XML Special Interest Group546used a more Java-like interface for this method.  Since most parsers used from547Python did not take advantage of the older interface, the simpler signature was548chosen to replace it.  To convert old code to the new interface, use <em>content</em>549instead of slicing content with the old <em>offset</em> and <em>length</em> parameters.</p>550</div>551</dd></dl>552 553<dl class="py method">554<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.ignorableWhitespace">555<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>556<dd><p>Receive notification of ignorable whitespace in element content.</p>557<p>Validating Parsers must use this method to report each chunk of ignorable558whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating559parsers may also use this method if they are capable of parsing and using560content models.</p>561<p>SAX parsers may return all contiguous whitespace in a single chunk, or they may562split it into several chunks; however, all of the characters in any single event563must come from the same external entity, so that the Locator provides useful564information.</p>565</dd></dl>566 567<dl class="py method">568<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.processingInstruction">569<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>570<dd><p>Receive notification of a processing instruction.</p>571<p>The Parser will invoke this method once for each processing instruction found:572note that processing instructions may occur before or after the main document573element.</p>574<p>A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a575text declaration (XML 1.0, section 4.3.1) using this method.</p>576</dd></dl>577 578<dl class="py method">579<dt class="sig sig-object py" id="xml.sax.handler.ContentHandler.skippedEntity">580<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>581<dd><p>Receive notification of a skipped entity.</p>582<p>The Parser will invoke this method once for each entity skipped. Non-validating583processors may skip entities if they have not seen the declarations (because,584for example, the entity was declared in an external DTD subset). All processors585may skip external entities, depending on the values of the586<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>587</dd></dl>588 589</section>590<section id="dtdhandler-objects">591<span id="dtd-handler-objects"></span><h2>DTDHandler Objects<a class="headerlink" href="#dtdhandler-objects" title="Link to this heading">¶</a></h2>592<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>593<dl class="py method">594<dt class="sig sig-object py" id="xml.sax.handler.DTDHandler.notationDecl">595<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>596<dd><p>Handle a notation declaration event.</p>597</dd></dl>598 599<dl class="py method">600<dt class="sig sig-object py" id="xml.sax.handler.DTDHandler.unparsedEntityDecl">601<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>602<dd><p>Handle an unparsed entity declaration event.</p>603</dd></dl>604 605</section>606<section id="entityresolver-objects">607<span id="entity-resolver-objects"></span><h2>EntityResolver Objects<a class="headerlink" href="#entityresolver-objects" title="Link to this heading">¶</a></h2>608<dl class="py method">609<dt class="sig sig-object py" id="xml.sax.handler.EntityResolver.resolveEntity">610<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>611<dd><p>Resolve the system identifier of an entity and return either the system612identifier to read from as a string, or an InputSource to read from. The default613implementation returns <em>systemId</em>.</p>614</dd></dl>615 616</section>617<section id="errorhandler-objects">618<span id="sax-error-handler"></span><h2>ErrorHandler Objects<a class="headerlink" href="#errorhandler-objects" title="Link to this heading">¶</a></h2>619<p>Objects with this interface are used to receive error and warning information620from 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 that621implements this interface, then register the object with your622<code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code>, the parser623will call the methods in your object to report all warnings and errors. There624are three levels of errors available: warnings, (possibly) recoverable errors,625and 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 the626only parameter.  Errors and warnings may be converted to an exception by raising627the passed-in exception object.</p>628<dl class="py method">629<dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler.error">630<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>631<dd><p>Called when the parser encounters a recoverable error.  If this method does not632raise an exception, parsing may continue, but further document information633should not be expected by the application.  Allowing the parser to continue may634allow additional errors to be discovered in the input document.</p>635</dd></dl>636 637<dl class="py method">638<dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler.fatalError">639<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>640<dd><p>Called when the parser encounters an error it cannot recover from; parsing is641expected to terminate when this method returns.</p>642</dd></dl>643 644<dl class="py method">645<dt class="sig sig-object py" id="xml.sax.handler.ErrorHandler.warning">646<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>647<dd><p>Called when the parser presents minor warning information to the application.648Parsing is expected to continue when this method returns, and document649information will continue to be passed to the application. Raising an exception650in this method will cause parsing to end.</p>651</dd></dl>652 653</section>654<section id="lexicalhandler-objects">655<span id="lexical-handler-objects"></span><h2>LexicalHandler Objects<a class="headerlink" href="#lexicalhandler-objects" title="Link to this heading">¶</a></h2>656<p>Optional SAX2 handler for lexical events.</p>657<p>This handler is used to obtain lexical information about an XML658document. Lexical information includes information describing the659document encoding used and XML comments embedded in the document, as660well as section boundaries for the DTD and for any CDATA sections.661The lexical handlers are used in the same manner as content handlers.</p>662<p>Set the LexicalHandler of an XMLReader by using the setProperty method663with the property identifier664<code class="docutils literal notranslate"><span class="pre">'http://xml.org/sax/properties/lexical-handler'</span></code>.</p>665<dl class="py method">666<dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.comment">667<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>668<dd><p>Reports a comment anywhere in the document (including the DTD and669outside the document element).</p>670</dd></dl>671 672<dl class="py method">673<dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.startDTD">674<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>675<dd><p>Reports the start of the DTD declarations if the document has an676associated DTD.</p>677</dd></dl>678 679<dl class="py method">680<dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.endDTD">681<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>682<dd><p>Reports the end of DTD declaration.</p>683</dd></dl>684 685<dl class="py method">686<dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.startCDATA">687<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>688<dd><p>Reports the start of a CDATA marked section.</p>689<p>The contents of the CDATA marked section will be reported through690the characters handler.</p>691</dd></dl>692 693<dl class="py method">694<dt class="sig sig-object py" id="xml.sax.handler.LexicalHandler.endCDATA">695<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>696<dd><p>Reports the end of a CDATA marked section.</p>697</dd></dl>698 699</section>700</section>701 702 703            <div class="clearer"></div>704          </div>705        </div>706      </div>707      <div class="sphinxsidebar" role="navigation" aria-label="Main">708        <div class="sphinxsidebarwrapper">709  <div>710    <h3><a href="../contents.html">Table of Contents</a></h3>711    <ul>712<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>713<li><a class="reference internal" href="#contenthandler-objects">ContentHandler Objects</a></li>714<li><a class="reference internal" href="#dtdhandler-objects">DTDHandler Objects</a></li>715<li><a class="reference internal" href="#entityresolver-objects">EntityResolver Objects</a></li>716<li><a class="reference internal" href="#errorhandler-objects">ErrorHandler Objects</a></li>717<li><a class="reference internal" href="#lexicalhandler-objects">LexicalHandler Objects</a></li>718</ul>719</li>720</ul>721 722  </div>723  <div>724    <h4>Previous topic</h4>725    <p class="topless"><a href="xml.sax.html"726                          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>727  </div>728  <div>729    <h4>Next topic</h4>730    <p class="topless"><a href="xml.sax.utils.html"731                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.saxutils</span></code> — SAX Utilities</a></p>732  </div>733  <script>734    document.addEventListener('DOMContentLoaded', () => {735        const title = document.querySelector('meta[property="og:title"]').content;736        const elements = document.querySelectorAll('.improvepage');737        const pageurl = window.location.href.split('?')[0];738        elements.forEach(element => {739            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));740            url.searchParams.set('pagetitle', title);741            url.searchParams.set('pageurl', pageurl);742            url.searchParams.set('pagesource', "library/xml.sax.handler.rst");743            element.href = url.toString();744        });745    });746  </script>747  <div role="note" aria-label="source link">748    <h3>This page</h3>749    <ul class="this-page-menu">750      <li><a href="../bugs.html">Report a bug</a></li>751      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>752      <li>753        <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.sax.handler.rst?plain=1"754            rel="nofollow">Show source755        </a>756      </li>757      758    </ul>759  </div>760        </div>761<div id="sidebarbutton" title="Collapse sidebar">762<span>«</span>763</div>764 765      </div>766      <div class="clearer"></div>767    </div>  768    <div class="related" role="navigation" aria-label="Related">769      <h3>Navigation</h3>770      <ul>771        <li class="right" style="margin-right: 10px">772          <a href="../genindex.html" title="General Index"773             >index</a></li>774        <li class="right" >775          <a href="../py-modindex.html" title="Python Module Index"776             >modules</a> |</li>777        <li class="right" >778          <a href="xml.sax.utils.html" title="xml.sax.saxutils — SAX Utilities"779             >next</a> |</li>780        <li class="right" >781          <a href="xml.sax.html" title="xml.sax — Support for SAX2 parsers"782             >previous</a> |</li>783 784          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>785          <li><a href="https://www.python.org/">Python</a> &#187;</li>786          <li class="switchers">787            <div class="language_switcher_placeholder"></div>788            <div class="version_switcher_placeholder"></div>789          </li>790          <li>791              792          </li>793    <li id="cpython-language-and-version">794      <a href="../index.html">3.15.0a6 Documentation</a> &#187;795    </li>796 797          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>798          <li class="nav-item nav-item-2"><a href="markup.html" >Structured Markup Processing Tools</a> &#187;</li>799        <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>800                <li class="right">801                    802 803    <div class="inline-search" role="search">804        <form class="inline-search" action="../search.html" method="get">805          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">806          <input type="submit" value="Go">807        </form>808    </div>809                     |810                </li>811            <li class="right">812<label class="theme-selector-label">813    Theme814    <select class="theme-selector" oninput="activateTheme(this.value)">815        <option value="auto" selected>Auto</option>816        <option value="light">Light</option>817        <option value="dark">Dark</option>818    </select>819</label> |</li>820            821      </ul>822    </div>  823    <div class="footer">824    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.825    <br>826    This page is licensed under the Python Software Foundation License Version 2.827    <br>828    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.829    <br>830    831      See <a href="/license.html">History and License</a> for more information.<br>832    833    834    <br>835 836    The Python Software Foundation is a non-profit corporation.837<a href="https://www.python.org/psf/donations/">Please donate.</a>838<br>839    <br>840      Last updated on Mar 10, 2026 (08:58 UTC).841    842      <a href="/bugs.html">Found a bug</a>?843    844    <br>845 846    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.847    </div>848 849  </body>850</html>