Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
pyexpat.html1504 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.parsers.expat — Fast XML parsing using Expat" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/pyexpat.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="The xml.parsers.expat module is a Python interface to the Expat non-validating XML parser. The module provides a single extension type, xmlparser, that represents the current state of an XML parser..." />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_pyexpat_8a9ce702.png" />15<meta property="og:image:alt" content="The xml.parsers.expat module is a Python interface to the Expat non-validating XML parser. The module provides a single extension type, xmlparser, that represents the current state of an XML parser..." />16<meta name="description" content="The xml.parsers.expat module is a Python interface to the Expat non-validating XML parser. The module provides a single extension type, xmlparser, that represents the current state of an XML parser..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>xml.parsers.expat — Fast XML parsing using Expat &#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="Internet Protocols and Support" href="internet.html" />43    <link rel="prev" title="xml.sax.xmlreader — Interface for XML parsers" href="xml.sax.reader.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/pyexpat.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.parsers.expat</span></code> — Fast XML parsing using Expat</a><ul>108<li><a class="reference internal" href="#xmlparser-objects">XMLParser Objects</a></li>109<li><a class="reference internal" href="#expaterror-exceptions">ExpatError Exceptions</a></li>110<li><a class="reference internal" href="#example">Example</a></li>111<li><a class="reference internal" href="#module-xml.parsers.expat.model">Content Model Descriptions</a></li>112<li><a class="reference internal" href="#module-xml.parsers.expat.errors">Expat error constants</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.reader.html"121                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.xmlreader</span></code> — Interface for XML parsers</a></p>122  </div>123  <div>124    <h4>Next topic</h4>125    <p class="topless"><a href="internet.html"126                          title="next chapter">Internet Protocols and Support</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/pyexpat.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/pyexpat.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="internet.html" title="Internet Protocols and Support"171             accesskey="N">next</a> |</li>172        <li class="right" >173          <a href="xml.sax.reader.html" title="xml.sax.xmlreader — Interface for XML 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.parsers.expat</span></code> — Fast XML parsing using Expat</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.parsers.expat">222<span id="xml-parsers-expat-fast-xml-parsing-using-expat"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.parsers.expat</span></code> — Fast XML parsing using Expat<a class="headerlink" href="#module-xml.parsers.expat" title="Link to this heading">¶</a></h1>223<hr class="docutils" />224<div class="admonition note">225<p class="admonition-title">Note</p>226<p>If you need to parse untrusted or unauthenticated data, see227<a class="reference internal" href="xml.html#xml-security"><span class="std std-ref">XML security</span></a>.</p>228</div>229<p id="index-0">The <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.parsers.expat</span></code> module is a Python interface to the Expat230non-validating XML parser. The module provides a single extension type,231<code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code>, that represents the current state of an XML parser.  After232an <code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> object has been created, various attributes of the object233can be set to handler functions.  When an XML document is then fed to the234parser, the handler functions are called for the character data and markup in235the XML document.</p>236<p id="index-1">This module uses the <code class="xref py py-mod docutils literal notranslate"><span class="pre">pyexpat</span></code> module to provide access to the Expat237parser.  Direct use of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">pyexpat</span></code> module is deprecated.</p>238<p>This module provides one exception and one type object:</p>239<dl class="py exception">240<dt class="sig sig-object py" id="xml.parsers.expat.ExpatError">241<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.</span></span><span class="sig-name descname"><span class="pre">ExpatError</span></span><a class="headerlink" href="#xml.parsers.expat.ExpatError" title="Link to this definition">¶</a></dt>242<dd><p>The exception raised when Expat reports an error.  See section243<a class="reference internal" href="#expaterror-objects"><span class="std std-ref">ExpatError Exceptions</span></a> for more information on interpreting Expat errors.</p>244</dd></dl>245 246<dl class="py exception">247<dt class="sig sig-object py" id="xml.parsers.expat.error">248<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.</span></span><span class="sig-name descname"><span class="pre">error</span></span><a class="headerlink" href="#xml.parsers.expat.error" title="Link to this definition">¶</a></dt>249<dd><p>Alias for <a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code></a>.</p>250</dd></dl>251 252<dl class="py data">253<dt class="sig sig-object py" id="xml.parsers.expat.XMLParserType">254<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.</span></span><span class="sig-name descname"><span class="pre">XMLParserType</span></span><a class="headerlink" href="#xml.parsers.expat.XMLParserType" title="Link to this definition">¶</a></dt>255<dd><p>The type of the return values from the <a class="reference internal" href="#xml.parsers.expat.ParserCreate" title="xml.parsers.expat.ParserCreate"><code class="xref py py-func docutils literal notranslate"><span class="pre">ParserCreate()</span></code></a> function.</p>256</dd></dl>257 258<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.parsers.expat</span></code> module contains two functions:</p>259<dl class="py function">260<dt class="sig sig-object py" id="xml.parsers.expat.ErrorString">261<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.</span></span><span class="sig-name descname"><span class="pre">ErrorString</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">errno</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.ErrorString" title="Link to this definition">¶</a></dt>262<dd><p>Returns an explanatory string for a given error number <em>errno</em>.</p>263</dd></dl>264 265<dl class="py function">266<dt class="sig sig-object py" id="xml.parsers.expat.ParserCreate">267<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.</span></span><span class="sig-name descname"><span class="pre">ParserCreate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">namespace_separator</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.ParserCreate" title="Link to this definition">¶</a></dt>268<dd><p>Creates and returns a new <code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> object.   <em>encoding</em>, if specified,269must be a string naming the encoding  used by the XML data.  Expat doesn’t270support as many encodings as Python does, and its repertoire of encodings can’t271be extended; it supports UTF-8, UTF-16, ISO-8859-1 (Latin1), and ASCII.  If272<em>encoding</em> <a class="footnote-reference brackets" href="#id3" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> is given it will override the implicit or explicit encoding of the273document.</p>274<p id="xmlparser-non-root">Parsers created through <code class="xref py py-func docutils literal notranslate"><span class="pre">ParserCreate()</span></code> are called “root” parsers,275in the sense that they do not have any parent parser attached. Non-root276parsers are created by <a class="reference internal" href="#xml.parsers.expat.xmlparser.ExternalEntityParserCreate" title="xml.parsers.expat.xmlparser.ExternalEntityParserCreate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">parser.ExternalEntityParserCreate</span></code></a>.</p>277<p>Expat can optionally do XML namespace processing for you, enabled by providing a278value for <em>namespace_separator</em>.  The value must be a one-character string; a279<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> will be raised if the string has an illegal length (<code class="docutils literal notranslate"><span class="pre">None</span></code>280is considered the same as omission).  When namespace processing is enabled,281element type names and attribute names that belong to a namespace will be282expanded.  The element name passed to the element handlers283<code class="xref py py-attr docutils literal notranslate"><span class="pre">StartElementHandler</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">EndElementHandler</span></code> will be the284concatenation of the namespace URI, the namespace separator character, and the285local part of the name.  If the namespace separator is a zero byte (<code class="docutils literal notranslate"><span class="pre">chr(0)</span></code>)286then the namespace URI and the local part will be concatenated without any287separator.</p>288<p>For example, if <em>namespace_separator</em> is set to a space character (<code class="docutils literal notranslate"><span class="pre">'</span> <span class="pre">'</span></code>) and289the following document is parsed:</p>290<div class="highlight-xml notranslate"><div class="highlight"><pre><span></span><span class="cp">&lt;?xml version=&quot;1.0&quot;?&gt;</span>291<span class="nt">&lt;root</span><span class="w"> </span><span class="na">xmlns    =</span><span class="w"> </span><span class="s">&quot;http://default-namespace.org/&quot;</span>292<span class="w">      </span><span class="na">xmlns:py =</span><span class="w"> </span><span class="s">&quot;http://www.python.org/ns/&quot;</span><span class="nt">&gt;</span>293<span class="w">  </span><span class="nt">&lt;py:elem1</span><span class="w"> </span><span class="nt">/&gt;</span>294<span class="w">  </span><span class="nt">&lt;elem2</span><span class="w"> </span><span class="na">xmlns=</span><span class="s">&quot;&quot;</span><span class="w"> </span><span class="nt">/&gt;</span>295<span class="nt">&lt;/root&gt;</span>296</pre></div>297</div>298<p><code class="xref py py-attr docutils literal notranslate"><span class="pre">StartElementHandler</span></code> will receive the following strings for each299element:</p>300<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">default</span><span class="o">-</span><span class="n">namespace</span><span class="o">.</span><span class="n">org</span><span class="o">/</span> <span class="n">root</span>301<span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">www</span><span class="o">.</span><span class="n">python</span><span class="o">.</span><span class="n">org</span><span class="o">/</span><span class="n">ns</span><span class="o">/</span> <span class="n">elem1</span>302<span class="n">elem2</span>303</pre></div>304</div>305<p>Due to limitations in the <code class="docutils literal notranslate"><span class="pre">Expat</span></code> library used by <code class="xref py py-mod docutils literal notranslate"><span class="pre">pyexpat</span></code>,306the <code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> instance returned can only be used to parse a single307XML document.  Call <code class="docutils literal notranslate"><span class="pre">ParserCreate</span></code> for each document to provide unique308parser instances.</p>309</dd></dl>310 311<div class="admonition seealso">312<p class="admonition-title">See also</p>313<dl class="simple">314<dt><a class="reference external" href="http://www.libexpat.org/">The Expat XML Parser</a></dt><dd><p>Home page of the Expat project.</p>315</dd>316</dl>317</div>318<section id="xmlparser-objects">319<span id="id2"></span><h2>XMLParser Objects<a class="headerlink" href="#xmlparser-objects" title="Link to this heading">¶</a></h2>320<p><code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> objects have the following methods:</p>321<dl class="py method">322<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.Parse">323<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">Parse</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">isfinal</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.Parse" title="Link to this definition">¶</a></dt>324<dd><p>Parses the contents of the string <em>data</em>, calling the appropriate handler325functions to process the parsed data.  <em>isfinal</em> must be true on the final call326to this method; it allows the parsing of a single file in fragments,327not the submission of multiple files.328<em>data</em> can be the empty string at any time.</p>329</dd></dl>330 331<dl class="py method">332<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ParseFile">333<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ParseFile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ParseFile" title="Link to this definition">¶</a></dt>334<dd><p>Parse XML data reading from the object <em>file</em>.  <em>file</em> only needs to provide335the <code class="docutils literal notranslate"><span class="pre">read(nbytes)</span></code> method, returning the empty string when there’s no more336data.</p>337</dd></dl>338 339<dl class="py method">340<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.SetBase">341<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">SetBase</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">base</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.SetBase" title="Link to this definition">¶</a></dt>342<dd><p>Sets the base to be used for resolving relative URIs in system identifiers in343declarations.  Resolving relative identifiers is left to the application: this344value will be passed through as the <em>base</em> argument to the345<a class="reference internal" href="#xml.parsers.expat.xmlparser.ExternalEntityRefHandler" title="xml.parsers.expat.xmlparser.ExternalEntityRefHandler"><code class="xref py py-func docutils literal notranslate"><span class="pre">ExternalEntityRefHandler()</span></code></a>, <a class="reference internal" href="#xml.parsers.expat.xmlparser.NotationDeclHandler" title="xml.parsers.expat.xmlparser.NotationDeclHandler"><code class="xref py py-func docutils literal notranslate"><span class="pre">NotationDeclHandler()</span></code></a>, and346<a class="reference internal" href="#xml.parsers.expat.xmlparser.UnparsedEntityDeclHandler" title="xml.parsers.expat.xmlparser.UnparsedEntityDeclHandler"><code class="xref py py-func docutils literal notranslate"><span class="pre">UnparsedEntityDeclHandler()</span></code></a> functions.</p>347</dd></dl>348 349<dl class="py method">350<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.GetBase">351<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">GetBase</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.GetBase" title="Link to this definition">¶</a></dt>352<dd><p>Returns a string containing the base set by a previous call to <a class="reference internal" href="#xml.parsers.expat.xmlparser.SetBase" title="xml.parsers.expat.xmlparser.SetBase"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetBase()</span></code></a>,353or <code class="docutils literal notranslate"><span class="pre">None</span></code> if  <code class="xref py py-meth docutils literal notranslate"><span class="pre">SetBase()</span></code> hasn’t been called.</p>354</dd></dl>355 356<dl class="py method">357<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.GetInputContext">358<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">GetInputContext</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.GetInputContext" title="Link to this definition">¶</a></dt>359<dd><p>Returns the input data that generated the current event as a string. The data is360in the encoding of the entity which contains the text. When called while an361event handler is not active, the return value is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>362</dd></dl>363 364<dl class="py method">365<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ExternalEntityParserCreate">366<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ExternalEntityParserCreate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ExternalEntityParserCreate" title="Link to this definition">¶</a></dt>367<dd><p>Create a “child” parser which can be used to parse an external parsed entity368referred to by content parsed by the parent parser.  The <em>context</em> parameter369should be the string passed to the <a class="reference internal" href="#xml.parsers.expat.xmlparser.ExternalEntityRefHandler" title="xml.parsers.expat.xmlparser.ExternalEntityRefHandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ExternalEntityRefHandler()</span></code></a> handler370function, described below. The child parser is created with the371<a class="reference internal" href="#xml.parsers.expat.xmlparser.ordered_attributes" title="xml.parsers.expat.xmlparser.ordered_attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ordered_attributes</span></code></a> and <a class="reference internal" href="#xml.parsers.expat.xmlparser.specified_attributes" title="xml.parsers.expat.xmlparser.specified_attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">specified_attributes</span></code></a> set to the values of372this parser.</p>373</dd></dl>374 375<dl class="py method">376<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.SetParamEntityParsing">377<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">SetParamEntityParsing</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">flag</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.SetParamEntityParsing" title="Link to this definition">¶</a></dt>378<dd><p>Control parsing of parameter entities (including the external DTD subset).379Possible <em>flag</em> values are <code class="xref py py-const docutils literal notranslate"><span class="pre">XML_PARAM_ENTITY_PARSING_NEVER</span></code>,380<code class="xref py py-const docutils literal notranslate"><span class="pre">XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</span></code> and381<code class="xref py py-const docutils literal notranslate"><span class="pre">XML_PARAM_ENTITY_PARSING_ALWAYS</span></code>.  Return true if setting the flag382was successful.</p>383</dd></dl>384 385<dl class="py method">386<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.UseForeignDTD">387<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">UseForeignDTD</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">flag</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.UseForeignDTD" title="Link to this definition">¶</a></dt>388<dd><p>Calling this with a true value for <em>flag</em> (the default) will cause Expat to call389the <a class="reference internal" href="#xml.parsers.expat.xmlparser.ExternalEntityRefHandler" title="xml.parsers.expat.xmlparser.ExternalEntityRefHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ExternalEntityRefHandler</span></code></a> with <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> for all arguments to390allow an alternate DTD to be loaded.  If the document does not contain a391document type declaration, the <code class="xref py py-attr docutils literal notranslate"><span class="pre">ExternalEntityRefHandler</span></code> will still be392called, but the <a class="reference internal" href="#xml.parsers.expat.xmlparser.StartDoctypeDeclHandler" title="xml.parsers.expat.xmlparser.StartDoctypeDeclHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">StartDoctypeDeclHandler</span></code></a> and393<a class="reference internal" href="#xml.parsers.expat.xmlparser.EndDoctypeDeclHandler" title="xml.parsers.expat.xmlparser.EndDoctypeDeclHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EndDoctypeDeclHandler</span></code></a> will not be called.</p>394<p>Passing a false value for <em>flag</em> will cancel a previous call that passed a true395value, but otherwise has no effect.</p>396<p>This method can only be called before the <a class="reference internal" href="#xml.parsers.expat.xmlparser.Parse" title="xml.parsers.expat.xmlparser.Parse"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Parse()</span></code></a> or <a class="reference internal" href="#xml.parsers.expat.xmlparser.ParseFile" title="xml.parsers.expat.xmlparser.ParseFile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ParseFile()</span></code></a>397methods are called; calling it after either of those have been called causes398<a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code></a> to be raised with the <a class="reference internal" href="code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-attr docutils literal notranslate"><span class="pre">code</span></code></a> attribute set to399<code class="docutils literal notranslate"><span class="pre">errors.codes[errors.XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING]</span></code>.</p>400</dd></dl>401 402<dl class="py method">403<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.SetReparseDeferralEnabled">404<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">SetReparseDeferralEnabled</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">enabled</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.SetReparseDeferralEnabled" title="Link to this definition">¶</a></dt>405<dd><div class="admonition warning">406<p class="admonition-title">Warning</p>407<p>Calling <code class="docutils literal notranslate"><span class="pre">SetReparseDeferralEnabled(False)</span></code> has security implications,408as detailed below; please make sure to understand these consequences409prior to using the <code class="docutils literal notranslate"><span class="pre">SetReparseDeferralEnabled</span></code> method.</p>410</div>411<p>Expat 2.6.0 introduced a security mechanism called “reparse deferral”412where instead of causing denial of service through quadratic runtime413from reparsing large tokens, reparsing of unfinished tokens is now delayed414by default until a sufficient amount of input is reached.415Due to this delay, registered handlers may — depending of the sizing of416input chunks pushed to Expat — no longer be called right after pushing new417input to the parser.  Where immediate feedback and taking over responsibility418of protecting against denial of service from large tokens are both wanted,419calling <code class="docutils literal notranslate"><span class="pre">SetReparseDeferralEnabled(False)</span></code> disables reparse deferral420for the current Expat parser instance, temporarily or altogether.421Calling <code class="docutils literal notranslate"><span class="pre">SetReparseDeferralEnabled(True)</span></code> allows re-enabling reparse422deferral.</p>423<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetReparseDeferralEnabled()</span></code>424has been backported to some prior releases of CPython as a security fix.425Check for availability using <a class="reference internal" href="functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a> if used in code running426across a variety of Python versions.</p>427<div class="versionadded">428<p><span class="versionmodified added">Added in version 3.13.</span></p>429</div>430</dd></dl>431 432<dl class="py method">433<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.GetReparseDeferralEnabled">434<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">GetReparseDeferralEnabled</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.GetReparseDeferralEnabled" title="Link to this definition">¶</a></dt>435<dd><p>Returns whether reparse deferral is currently enabled for the given436Expat parser instance.</p>437<div class="versionadded">438<p><span class="versionmodified added">Added in version 3.13.</span></p>439</div>440</dd></dl>441 442<p><code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> objects have the following methods to tune protections443against some common XML vulnerabilities.</p>444<dl class="py method">445<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold">446<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">SetBillionLaughsAttackProtectionActivationThreshold</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">threshold</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold" title="Link to this definition">¶</a></dt>447<dd><p>Sets the number of output bytes needed to activate protection against448<a class="reference external" href="https://en.wikipedia.org/wiki/Billion_laughs_attack">billion laughs</a> attacks.</p>449<p>The number of output bytes includes amplification from entity expansion450and reading DTD files.</p>451<p>Parser objects usually have a protection activation threshold of 8 MiB,452but the actual default value depends on the underlying Expat library.</p>453<p>An <a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code></a> is raised if this method is called on a454<a class="reference internal" href="#xmlparser-non-root"><span class="std std-ref">non-root</span></a> parser.455The corresponding <a class="reference internal" href="#xml.parsers.expat.ExpatError.lineno" title="xml.parsers.expat.ExpatError.lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">lineno</span></code></a> and <a class="reference internal" href="#xml.parsers.expat.ExpatError.offset" title="xml.parsers.expat.ExpatError.offset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">offset</span></code></a>456should not be used as they may have no special meaning.</p>457<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetBillionLaughsAttackProtectionActivationThreshold()</span></code>458has been backported to some prior releases of CPython as a security fix.459Check for availability using <a class="reference internal" href="functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a> if used in code running460across a variety of Python versions.</p>461<div class="admonition note">462<p class="admonition-title">Note</p>463<p>Activation thresholds below 4 MiB are known to break support for DITA 1.3464payload and are hence not recommended.</p>465</div>466<div class="versionadded">467<p><span class="versionmodified added">Added in version 3.15.</span></p>468</div>469</dd></dl>470 471<dl class="py method">472<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionMaximumAmplification">473<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">SetBillionLaughsAttackProtectionMaximumAmplification</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">max_factor</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionMaximumAmplification" title="Link to this definition">¶</a></dt>474<dd><p>Sets the maximum tolerated amplification factor for protection against475<a class="reference external" href="https://en.wikipedia.org/wiki/Billion_laughs_attack">billion laughs</a> attacks.</p>476<p>The amplification factor is calculated as <code class="docutils literal notranslate"><span class="pre">(direct</span> <span class="pre">+</span> <span class="pre">indirect)</span> <span class="pre">/</span> <span class="pre">direct</span></code>477while parsing, where <code class="docutils literal notranslate"><span class="pre">direct</span></code> is the number of bytes read from478the primary document in parsing and <code class="docutils literal notranslate"><span class="pre">indirect</span></code> is the number of479bytes added by expanding entities and reading of external DTD files.</p>480<p>The <em>max_factor</em> value must be a non-NaN <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> value greater than481or equal to 1.0. Peak amplifications of factor 15,000 for the entire payload482and of factor 30,000 in the middle of parsing have been observed with small483benign files in practice. In particular, the activation threshold should be484carefully chosen to avoid false positives.</p>485<p>Parser objects usually have a maximum amplification factor of 100,486but the actual default value depends on the underlying Expat library.</p>487<p>An <a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code></a> is raised if this method is called on a488<a class="reference internal" href="#xmlparser-non-root"><span class="std std-ref">non-root</span></a> parser or if <em>max_factor</em> is outside the valid range.489The corresponding <a class="reference internal" href="#xml.parsers.expat.ExpatError.lineno" title="xml.parsers.expat.ExpatError.lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">lineno</span></code></a> and <a class="reference internal" href="#xml.parsers.expat.ExpatError.offset" title="xml.parsers.expat.ExpatError.offset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">offset</span></code></a>490should not be used as they may have no special meaning.</p>491<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetBillionLaughsAttackProtectionMaximumAmplification()</span></code>492has been backported to some prior releases of CPython as a security fix.493Check for availability using <a class="reference internal" href="functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a> if used in code running494across a variety of Python versions.</p>495<div class="admonition note">496<p class="admonition-title">Note</p>497<p>The maximum amplification factor is only considered if the threshold498that can be adjusted by <a class="reference internal" href="#xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold" title="xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetBillionLaughsAttackProtectionActivationThreshold()</span></code></a>499is exceeded.</p>500</div>501<div class="versionadded">502<p><span class="versionmodified added">Added in version 3.15.</span></p>503</div>504</dd></dl>505 506<dl class="py method">507<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.SetAllocTrackerActivationThreshold">508<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">SetAllocTrackerActivationThreshold</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">threshold</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.SetAllocTrackerActivationThreshold" title="Link to this definition">¶</a></dt>509<dd><p>Sets the number of allocated bytes of dynamic memory needed to activate510protection against disproportionate use of RAM.</p>511<p>Parser objects usually have an allocation activation threshold of 64 MiB,512but the actual default value depends on the underlying Expat library.</p>513<p>An <a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code></a> is raised if this method is called on a514<a class="reference internal" href="#xmlparser-non-root"><span class="std std-ref">non-root</span></a> parser.515The corresponding <a class="reference internal" href="#xml.parsers.expat.ExpatError.lineno" title="xml.parsers.expat.ExpatError.lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">lineno</span></code></a> and <a class="reference internal" href="#xml.parsers.expat.ExpatError.offset" title="xml.parsers.expat.ExpatError.offset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">offset</span></code></a>516should not be used as they may have no special meaning.</p>517<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetAllocTrackerActivationThreshold()</span></code>518has been backported to some prior releases of CPython as a security fix.519Check for availability using <a class="reference internal" href="functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a> if used in code running520across a variety of Python versions.</p>521<div class="versionadded">522<p><span class="versionmodified added">Added in version 3.15.</span></p>523</div>524</dd></dl>525 526<dl class="py method">527<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.SetAllocTrackerMaximumAmplification">528<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">SetAllocTrackerMaximumAmplification</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">max_factor</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.SetAllocTrackerMaximumAmplification" title="Link to this definition">¶</a></dt>529<dd><p>Sets the maximum amplification factor between direct input and bytes530of dynamic memory allocated.</p>531<p>The amplification factor is calculated as <code class="docutils literal notranslate"><span class="pre">allocated</span> <span class="pre">/</span> <span class="pre">direct</span></code>532while parsing, where <code class="docutils literal notranslate"><span class="pre">direct</span></code> is the number of bytes read from533the primary document in parsing and <code class="docutils literal notranslate"><span class="pre">allocated</span></code> is the number534of bytes of dynamic memory allocated in the parser hierarchy.</p>535<p>The <em>max_factor</em> value must be a non-NaN <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> value greater than536or equal to 1.0. Amplification factors greater than 100.0 can be observed537near the start of parsing even with benign files in practice. In particular,538the activation threshold should be carefully chosen to avoid false positives.</p>539<p>Parser objects usually have a maximum amplification factor of 100,540but the actual default value depends on the underlying Expat library.</p>541<p>An <a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code></a> is raised if this method is called on a542<a class="reference internal" href="#xmlparser-non-root"><span class="std std-ref">non-root</span></a> parser or if <em>max_factor</em> is outside the valid range.543The corresponding <a class="reference internal" href="#xml.parsers.expat.ExpatError.lineno" title="xml.parsers.expat.ExpatError.lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">lineno</span></code></a> and <a class="reference internal" href="#xml.parsers.expat.ExpatError.offset" title="xml.parsers.expat.ExpatError.offset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">offset</span></code></a>544should not be used as they may have no special meaning.</p>545<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetAllocTrackerMaximumAmplification()</span></code>546has been backported to some prior releases of CPython as a security fix.547Check for availability using <a class="reference internal" href="functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a> if used in code running548across a variety of Python versions.</p>549<div class="admonition note">550<p class="admonition-title">Note</p>551<p>The maximum amplification factor is only considered if the threshold552that can be adjusted by <a class="reference internal" href="#xml.parsers.expat.xmlparser.SetAllocTrackerActivationThreshold" title="xml.parsers.expat.xmlparser.SetAllocTrackerActivationThreshold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetAllocTrackerActivationThreshold()</span></code></a>553is exceeded.</p>554</div>555<div class="versionadded">556<p><span class="versionmodified added">Added in version 3.15.</span></p>557</div>558</dd></dl>559 560<p><code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> objects have the following attributes:</p>561<dl class="py attribute">562<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.buffer_size">563<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">buffer_size</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.buffer_size" title="Link to this definition">¶</a></dt>564<dd><p>The size of the buffer used when <a class="reference internal" href="#xml.parsers.expat.xmlparser.buffer_text" title="xml.parsers.expat.xmlparser.buffer_text"><code class="xref py py-attr docutils literal notranslate"><span class="pre">buffer_text</span></code></a> is true.565A new buffer size can be set by assigning a new integer value566to this attribute.567When the size is changed, the buffer will be flushed.</p>568</dd></dl>569 570<dl class="py attribute">571<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.buffer_text">572<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">buffer_text</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.buffer_text" title="Link to this definition">¶</a></dt>573<dd><p>Setting this to true causes the <code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> object to buffer textual574content returned by Expat to avoid multiple calls to the575<a class="reference internal" href="#xml.parsers.expat.xmlparser.CharacterDataHandler" title="xml.parsers.expat.xmlparser.CharacterDataHandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">CharacterDataHandler()</span></code></a> callback whenever possible.  This can improve576performance substantially since Expat normally breaks character data into chunks577at every line ending.  This attribute is false by default, and may be changed at578any time. Note that when it is false, data that does not contain newlines579may be chunked too.</p>580</dd></dl>581 582<dl class="py attribute">583<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.buffer_used">584<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">buffer_used</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.buffer_used" title="Link to this definition">¶</a></dt>585<dd><p>If <a class="reference internal" href="#xml.parsers.expat.xmlparser.buffer_text" title="xml.parsers.expat.xmlparser.buffer_text"><code class="xref py py-attr docutils literal notranslate"><span class="pre">buffer_text</span></code></a> is enabled, the number of bytes stored in the buffer.586These bytes represent UTF-8 encoded text.  This attribute has no meaningful587interpretation when <code class="xref py py-attr docutils literal notranslate"><span class="pre">buffer_text</span></code> is false.</p>588</dd></dl>589 590<dl class="py attribute">591<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ordered_attributes">592<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ordered_attributes</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ordered_attributes" title="Link to this definition">¶</a></dt>593<dd><p>Setting this attribute to a non-zero integer causes the attributes to be594reported as a list rather than a dictionary.  The attributes are presented in595the order found in the document text.  For each attribute, two list entries are596presented: the attribute name and the attribute value.  (Older versions of this597module also used this format.)  By default, this attribute is false; it may be598changed at any time.</p>599</dd></dl>600 601<dl class="py attribute">602<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.specified_attributes">603<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">specified_attributes</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.specified_attributes" title="Link to this definition">¶</a></dt>604<dd><p>If set to a non-zero integer, the parser will report only those attributes which605were specified in the document instance and not those which were derived from606attribute declarations.  Applications which set this need to be especially607careful to use what additional information is available from the declarations as608needed to comply with the standards for the behavior of XML processors.  By609default, this attribute is false; it may be changed at any time.</p>610</dd></dl>611 612<p>The following attributes contain values relating to the most recent error613encountered by an <code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> object, and will only have correct values614once a call to <code class="xref py py-meth docutils literal notranslate"><span class="pre">Parse()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">ParseFile()</span></code> has raised an615<a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">xml.parsers.expat.ExpatError</span></code></a> exception.</p>616<dl class="py attribute">617<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ErrorByteIndex">618<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ErrorByteIndex</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ErrorByteIndex" title="Link to this definition">¶</a></dt>619<dd><p>Byte index at which an error occurred.</p>620</dd></dl>621 622<dl class="py attribute">623<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ErrorCode">624<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ErrorCode</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ErrorCode" title="Link to this definition">¶</a></dt>625<dd><p>Numeric code specifying the problem.  This value can be passed to the626<a class="reference internal" href="#xml.parsers.expat.ErrorString" title="xml.parsers.expat.ErrorString"><code class="xref py py-func docutils literal notranslate"><span class="pre">ErrorString()</span></code></a> function, or compared to one of the constants defined in the627<code class="docutils literal notranslate"><span class="pre">errors</span></code> object.</p>628</dd></dl>629 630<dl class="py attribute">631<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ErrorColumnNumber">632<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ErrorColumnNumber</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ErrorColumnNumber" title="Link to this definition">¶</a></dt>633<dd><p>Column number at which an error occurred.</p>634</dd></dl>635 636<dl class="py attribute">637<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ErrorLineNumber">638<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ErrorLineNumber</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ErrorLineNumber" title="Link to this definition">¶</a></dt>639<dd><p>Line number at which an error occurred.</p>640</dd></dl>641 642<p>The following attributes contain values relating to the current parse location643in an <code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> object.  During a callback reporting a parse event they644indicate the location of the first of the sequence of characters that generated645the event.  When called outside of a callback, the position indicated will be646just past the last parse event (regardless of whether there was an associated647callback).</p>648<dl class="py attribute">649<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.CurrentByteIndex">650<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">CurrentByteIndex</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.CurrentByteIndex" title="Link to this definition">¶</a></dt>651<dd><p>Current byte index in the parser input.</p>652</dd></dl>653 654<dl class="py attribute">655<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.CurrentColumnNumber">656<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">CurrentColumnNumber</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.CurrentColumnNumber" title="Link to this definition">¶</a></dt>657<dd><p>Current column number in the parser input.</p>658</dd></dl>659 660<dl class="py attribute">661<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.CurrentLineNumber">662<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">CurrentLineNumber</span></span><a class="headerlink" href="#xml.parsers.expat.xmlparser.CurrentLineNumber" title="Link to this definition">¶</a></dt>663<dd><p>Current line number in the parser input.</p>664</dd></dl>665 666<p>Here is the list of handlers that can be set.  To set a handler on an667<code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> object <em>o</em>, use <code class="docutils literal notranslate"><span class="pre">o.handlername</span> <span class="pre">=</span> <span class="pre">func</span></code>.  <em>handlername</em> must668be taken from the following list, and <em>func</em> must be a callable object accepting669the correct number of arguments.  The arguments are all strings, unless670otherwise stated.</p>671<dl class="py method">672<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.XmlDeclHandler">673<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">XmlDeclHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">version</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">standalone</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.XmlDeclHandler" title="Link to this definition">¶</a></dt>674<dd><p>Called when the XML declaration is parsed.  The XML declaration is the675(optional) declaration of the applicable version of the XML recommendation, the676encoding of the document text, and an optional “standalone” declaration.677<em>version</em> and <em>encoding</em> will be strings, and <em>standalone</em> will be <code class="docutils literal notranslate"><span class="pre">1</span></code> if the678document is declared standalone, <code class="docutils literal notranslate"><span class="pre">0</span></code> if it is declared not to be standalone,679or <code class="docutils literal notranslate"><span class="pre">-1</span></code> if the standalone clause was omitted. This is only available with680Expat version 1.95.0 or newer.</p>681</dd></dl>682 683<dl class="py method">684<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.StartDoctypeDeclHandler">685<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">StartDoctypeDeclHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">doctypeName</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">publicId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">has_internal_subset</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.StartDoctypeDeclHandler" title="Link to this definition">¶</a></dt>686<dd><p>Called when Expat begins parsing the document type declaration (<code class="docutils literal notranslate"><span class="pre">&lt;!DOCTYPE</span>687<span class="pre">...</span></code>).  The <em>doctypeName</em> is provided exactly as presented.  The <em>systemId</em> and688<em>publicId</em> parameters give the system and public identifiers if specified, or689<code class="docutils literal notranslate"><span class="pre">None</span></code> if omitted.  <em>has_internal_subset</em> will be true if the document690contains an internal document declaration subset. This requires Expat version6911.2 or newer.</p>692</dd></dl>693 694<dl class="py method">695<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.EndDoctypeDeclHandler">696<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">EndDoctypeDeclHandler</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.EndDoctypeDeclHandler" title="Link to this definition">¶</a></dt>697<dd><p>Called when Expat is done parsing the document type declaration. This requires698Expat version 1.2 or newer.</p>699</dd></dl>700 701<dl class="py method">702<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ElementDeclHandler">703<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ElementDeclHandler</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">model</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ElementDeclHandler" title="Link to this definition">¶</a></dt>704<dd><p>Called once for each element type declaration.  <em>name</em> is the name of the705element type, and <em>model</em> is a representation of the content model.</p>706</dd></dl>707 708<dl class="py method">709<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.AttlistDeclHandler">710<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">AttlistDeclHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">elname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">required</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.AttlistDeclHandler" title="Link to this definition">¶</a></dt>711<dd><p>Called for each declared attribute for an element type.  If an attribute list712declaration declares three attributes, this handler is called three times, once713for each attribute.  <em>elname</em> is the name of the element to which the714declaration applies and <em>attname</em> is the name of the attribute declared.  The715attribute type is a string passed as <em>type</em>; the possible values are716<code class="docutils literal notranslate"><span class="pre">'CDATA'</span></code>, <code class="docutils literal notranslate"><span class="pre">'ID'</span></code>, <code class="docutils literal notranslate"><span class="pre">'IDREF'</span></code>, … <em>default</em> gives the default value for717the attribute used when the attribute is not specified by the document instance,718or <code class="docutils literal notranslate"><span class="pre">None</span></code> if there is no default value (<code class="docutils literal notranslate"><span class="pre">#IMPLIED</span></code> values).  If the719attribute is required to be given in the document instance, <em>required</em> will be720true. This requires Expat version 1.95.0 or newer.</p>721</dd></dl>722 723<dl class="py method">724<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.StartElementHandler">725<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">StartElementHandler</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">attributes</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.StartElementHandler" title="Link to this definition">¶</a></dt>726<dd><p>Called for the start of every element.  <em>name</em> is a string containing the727element name, and <em>attributes</em> is the element attributes. If728<a class="reference internal" href="#xml.parsers.expat.xmlparser.ordered_attributes" title="xml.parsers.expat.xmlparser.ordered_attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ordered_attributes</span></code></a> is true, this is a list (see729<code class="xref py py-attr docutils literal notranslate"><span class="pre">ordered_attributes</span></code> for a full description). Otherwise it’s a730dictionary mapping names to values.</p>731</dd></dl>732 733<dl class="py method">734<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.EndElementHandler">735<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">EndElementHandler</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.parsers.expat.xmlparser.EndElementHandler" title="Link to this definition">¶</a></dt>736<dd><p>Called for the end of every element.</p>737</dd></dl>738 739<dl class="py method">740<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ProcessingInstructionHandler">741<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ProcessingInstructionHandler</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.parsers.expat.xmlparser.ProcessingInstructionHandler" title="Link to this definition">¶</a></dt>742<dd><p>Called for every processing instruction.</p>743</dd></dl>744 745<dl class="py method">746<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.CharacterDataHandler">747<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">CharacterDataHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.CharacterDataHandler" title="Link to this definition">¶</a></dt>748<dd><p>Called for character data.  This will be called for normal character data, CDATA749marked content, and ignorable whitespace.  Applications which must distinguish750these cases can use the <a class="reference internal" href="#xml.parsers.expat.xmlparser.StartCdataSectionHandler" title="xml.parsers.expat.xmlparser.StartCdataSectionHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">StartCdataSectionHandler</span></code></a>,751<a class="reference internal" href="#xml.parsers.expat.xmlparser.EndCdataSectionHandler" title="xml.parsers.expat.xmlparser.EndCdataSectionHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EndCdataSectionHandler</span></code></a>, and <a class="reference internal" href="#xml.parsers.expat.xmlparser.ElementDeclHandler" title="xml.parsers.expat.xmlparser.ElementDeclHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ElementDeclHandler</span></code></a> callbacks to752collect the required information. Note that the character data may be753chunked even if it is short and so you may receive more than one call to754<code class="xref py py-meth docutils literal notranslate"><span class="pre">CharacterDataHandler()</span></code>. Set the <a class="reference internal" href="#xml.parsers.expat.xmlparser.buffer_text" title="xml.parsers.expat.xmlparser.buffer_text"><code class="xref py py-attr docutils literal notranslate"><span class="pre">buffer_text</span></code></a> instance attribute755to <code class="docutils literal notranslate"><span class="pre">True</span></code> to avoid that.</p>756</dd></dl>757 758<dl class="py method">759<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.UnparsedEntityDeclHandler">760<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">UnparsedEntityDeclHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">entityName</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">base</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">publicId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">notationName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.UnparsedEntityDeclHandler" title="Link to this definition">¶</a></dt>761<dd><p>Called for unparsed (NDATA) entity declarations.  This is only present for762version 1.2 of the Expat library; for more recent versions, use763<a class="reference internal" href="#xml.parsers.expat.xmlparser.EntityDeclHandler" title="xml.parsers.expat.xmlparser.EntityDeclHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EntityDeclHandler</span></code></a> instead.  (The underlying function in the Expat764library has been declared obsolete.)</p>765</dd></dl>766 767<dl class="py method">768<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.EntityDeclHandler">769<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">EntityDeclHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">entityName</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">is_parameter_entity</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">base</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">publicId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">notationName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.EntityDeclHandler" title="Link to this definition">¶</a></dt>770<dd><p>Called for all entity declarations.  For parameter and internal entities,771<em>value</em> will be a string giving the declared contents of the entity; this will772be <code class="docutils literal notranslate"><span class="pre">None</span></code> for external entities.  The <em>notationName</em> parameter will be773<code class="docutils literal notranslate"><span class="pre">None</span></code> for parsed entities, and the name of the notation for unparsed774entities. <em>is_parameter_entity</em> will be true if the entity is a parameter entity775or false for general entities (most applications only need to be concerned with776general entities). This is only available starting with version 1.95.0 of the777Expat library.</p>778</dd></dl>779 780<dl class="py method">781<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.NotationDeclHandler">782<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">NotationDeclHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">notationName</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">base</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">publicId</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.NotationDeclHandler" title="Link to this definition">¶</a></dt>783<dd><p>Called for notation declarations.  <em>notationName</em>, <em>base</em>, and <em>systemId</em>, and784<em>publicId</em> are strings if given.  If the public identifier is omitted,785<em>publicId</em> will be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>786</dd></dl>787 788<dl class="py method">789<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.StartNamespaceDeclHandler">790<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">StartNamespaceDeclHandler</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.parsers.expat.xmlparser.StartNamespaceDeclHandler" title="Link to this definition">¶</a></dt>791<dd><p>Called when an element contains a namespace declaration.  Namespace declarations792are processed before the <a class="reference internal" href="#xml.parsers.expat.xmlparser.StartElementHandler" title="xml.parsers.expat.xmlparser.StartElementHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">StartElementHandler</span></code></a> is called for the element793on which declarations are placed.</p>794</dd></dl>795 796<dl class="py method">797<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.EndNamespaceDeclHandler">798<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">EndNamespaceDeclHandler</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.parsers.expat.xmlparser.EndNamespaceDeclHandler" title="Link to this definition">¶</a></dt>799<dd><p>Called when the closing tag is reached for an element  that contained a800namespace declaration.  This is called once for each namespace declaration on801the element in the reverse of the order for which the802<a class="reference internal" href="#xml.parsers.expat.xmlparser.StartNamespaceDeclHandler" title="xml.parsers.expat.xmlparser.StartNamespaceDeclHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">StartNamespaceDeclHandler</span></code></a> was called to indicate the start of each803namespace declaration’s scope.  Calls to this handler are made after the804corresponding <a class="reference internal" href="#xml.parsers.expat.xmlparser.EndElementHandler" title="xml.parsers.expat.xmlparser.EndElementHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EndElementHandler</span></code></a> for the end of the element.</p>805</dd></dl>806 807<dl class="py method">808<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.CommentHandler">809<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">CommentHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.CommentHandler" title="Link to this definition">¶</a></dt>810<dd><p>Called for comments.  <em>data</em> is the text of the comment, excluding the leading811<code class="docutils literal notranslate"><span class="pre">'&lt;!-</span></code><code class="docutils literal notranslate"><span class="pre">-'</span></code> and trailing <code class="docutils literal notranslate"><span class="pre">'-</span></code><code class="docutils literal notranslate"><span class="pre">-&gt;'</span></code>.</p>812</dd></dl>813 814<dl class="py method">815<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.StartCdataSectionHandler">816<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">StartCdataSectionHandler</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.StartCdataSectionHandler" title="Link to this definition">¶</a></dt>817<dd><p>Called at the start of a CDATA section.  This and <a class="reference internal" href="#xml.parsers.expat.xmlparser.EndCdataSectionHandler" title="xml.parsers.expat.xmlparser.EndCdataSectionHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EndCdataSectionHandler</span></code></a>818are needed to be able to identify the syntactical start and end for CDATA819sections.</p>820</dd></dl>821 822<dl class="py method">823<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.EndCdataSectionHandler">824<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">EndCdataSectionHandler</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.EndCdataSectionHandler" title="Link to this definition">¶</a></dt>825<dd><p>Called at the end of a CDATA section.</p>826</dd></dl>827 828<dl class="py method">829<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.DefaultHandler">830<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">DefaultHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.DefaultHandler" title="Link to this definition">¶</a></dt>831<dd><p>Called for any characters in the XML document for which no applicable handler832has been specified.  This means characters that are part of a construct which833could be reported, but for which no handler has been supplied.</p>834</dd></dl>835 836<dl class="py method">837<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.DefaultHandlerExpand">838<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">DefaultHandlerExpand</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.DefaultHandlerExpand" title="Link to this definition">¶</a></dt>839<dd><p>This is the same as the <a class="reference internal" href="#xml.parsers.expat.xmlparser.DefaultHandler" title="xml.parsers.expat.xmlparser.DefaultHandler"><code class="xref py py-func docutils literal notranslate"><span class="pre">DefaultHandler()</span></code></a>,  but doesn’t inhibit expansion840of internal entities. The entity reference will not be passed to the default841handler.</p>842</dd></dl>843 844<dl class="py method">845<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.NotStandaloneHandler">846<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">NotStandaloneHandler</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.NotStandaloneHandler" title="Link to this definition">¶</a></dt>847<dd><p>Called if the XML document hasn’t been declared as being a standalone document.848This happens when there is an external subset or a reference to a parameter849entity, but the XML declaration does not set standalone to <code class="docutils literal notranslate"><span class="pre">yes</span></code> in an XML850declaration.  If this handler returns <code class="docutils literal notranslate"><span class="pre">0</span></code>, then the parser will raise an851<code class="xref py py-const docutils literal notranslate"><span class="pre">XML_ERROR_NOT_STANDALONE</span></code> error.  If this handler is not set, no852exception is raised by the parser for this condition.</p>853</dd></dl>854 855<dl class="py method">856<dt class="sig sig-object py" id="xml.parsers.expat.xmlparser.ExternalEntityRefHandler">857<span class="sig-prename descclassname"><span class="pre">xmlparser.</span></span><span class="sig-name descname"><span class="pre">ExternalEntityRefHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">base</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">publicId</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.parsers.expat.xmlparser.ExternalEntityRefHandler" title="Link to this definition">¶</a></dt>858<dd><div class="admonition warning">859<p class="admonition-title">Warning</p>860<p>Implementing a handler that accesses local files and/or the network861may create a vulnerability to862<a class="reference external" href="https://en.wikipedia.org/wiki/XML_external_entity_attack">external entity attacks</a>863if <code class="xref py py-class docutils literal notranslate"><span class="pre">xmlparser</span></code> is used with user-provided XML content.864Please reflect on your <a class="reference external" href="https://en.wikipedia.org/wiki/Threat_model">threat model</a>865before implementing this handler.</p>866</div>867<p>Called for references to external entities.  <em>base</em> is the current base, as set868by a previous call to <a class="reference internal" href="#xml.parsers.expat.xmlparser.SetBase" title="xml.parsers.expat.xmlparser.SetBase"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetBase()</span></code></a>.  The public and system identifiers,869<em>systemId</em> and <em>publicId</em>, are strings if given; if the public identifier is not870given, <em>publicId</em> will be <code class="docutils literal notranslate"><span class="pre">None</span></code>.  The <em>context</em> value is opaque and should871only be used as described below.</p>872<p>For external entities to be parsed, this handler must be implemented. It is873responsible for creating the sub-parser using874<code class="docutils literal notranslate"><span class="pre">ExternalEntityParserCreate(context)</span></code>, initializing it with the appropriate875callbacks, and parsing the entity.  This handler should return an integer; if it876returns <code class="docutils literal notranslate"><span class="pre">0</span></code>, the parser will raise an877<code class="xref py py-const docutils literal notranslate"><span class="pre">XML_ERROR_EXTERNAL_ENTITY_HANDLING</span></code> error, otherwise parsing will878continue.</p>879<p>If this handler is not provided, external entities are reported by the880<a class="reference internal" href="#xml.parsers.expat.xmlparser.DefaultHandler" title="xml.parsers.expat.xmlparser.DefaultHandler"><code class="xref py py-attr docutils literal notranslate"><span class="pre">DefaultHandler</span></code></a> callback, if provided.</p>881</dd></dl>882 883</section>884<section id="expaterror-exceptions">885<span id="expaterror-objects"></span><h2>ExpatError Exceptions<a class="headerlink" href="#expaterror-exceptions" title="Link to this heading">¶</a></h2>886<p><a class="reference internal" href="#xml.parsers.expat.ExpatError" title="xml.parsers.expat.ExpatError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code></a> exceptions have a number of interesting attributes:</p>887<dl class="py attribute">888<dt class="sig sig-object py" id="xml.parsers.expat.ExpatError.code">889<span class="sig-prename descclassname"><span class="pre">ExpatError.</span></span><span class="sig-name descname"><span class="pre">code</span></span><a class="headerlink" href="#xml.parsers.expat.ExpatError.code" title="Link to this definition">¶</a></dt>890<dd><p>Expat’s internal error number for the specific error.  The891<a class="reference internal" href="#xml.parsers.expat.errors.messages" title="xml.parsers.expat.errors.messages"><code class="xref py py-data docutils literal notranslate"><span class="pre">errors.messages</span></code></a> dictionary maps892these error numbers to Expat’s error messages.  For example:</p>893<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">xml.parsers.expat</span><span class="w"> </span><span class="kn">import</span> <span class="n">ParserCreate</span><span class="p">,</span> <span class="n">ExpatError</span><span class="p">,</span> <span class="n">errors</span>894 895<span class="n">p</span> <span class="o">=</span> <span class="n">ParserCreate</span><span class="p">()</span>896<span class="k">try</span><span class="p">:</span>897    <span class="n">p</span><span class="o">.</span><span class="n">Parse</span><span class="p">(</span><span class="n">some_xml_document</span><span class="p">)</span>898<span class="k">except</span> <span class="n">ExpatError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>899    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Error:&quot;</span><span class="p">,</span> <span class="n">errors</span><span class="o">.</span><span class="n">messages</span><span class="p">[</span><span class="n">err</span><span class="o">.</span><span class="n">code</span><span class="p">])</span>900</pre></div>901</div>902<p>The <a class="reference internal" href="#module-xml.parsers.expat.errors" title="xml.parsers.expat.errors"><code class="xref py py-mod docutils literal notranslate"><span class="pre">errors</span></code></a> module also provides error message903constants and a dictionary <a class="reference internal" href="#xml.parsers.expat.errors.codes" title="xml.parsers.expat.errors.codes"><code class="xref py py-data docutils literal notranslate"><span class="pre">codes</span></code></a> mapping904these messages back to the error codes, see below.</p>905</dd></dl>906 907<dl class="py attribute">908<dt class="sig sig-object py" id="xml.parsers.expat.ExpatError.lineno">909<span class="sig-prename descclassname"><span class="pre">ExpatError.</span></span><span class="sig-name descname"><span class="pre">lineno</span></span><a class="headerlink" href="#xml.parsers.expat.ExpatError.lineno" title="Link to this definition">¶</a></dt>910<dd><p>Line number on which the error was detected.  The first line is numbered <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>911</dd></dl>912 913<dl class="py attribute">914<dt class="sig sig-object py" id="xml.parsers.expat.ExpatError.offset">915<span class="sig-prename descclassname"><span class="pre">ExpatError.</span></span><span class="sig-name descname"><span class="pre">offset</span></span><a class="headerlink" href="#xml.parsers.expat.ExpatError.offset" title="Link to this definition">¶</a></dt>916<dd><p>Character offset into the line where the error occurred.  The first column is917numbered <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>918</dd></dl>919 920</section>921<section id="example">922<span id="expat-example"></span><h2>Example<a class="headerlink" href="#example" title="Link to this heading">¶</a></h2>923<p>The following program defines three handlers that just print out their924arguments.</p>925<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">xml.parsers.expat</span>926 927<span class="c1"># 3 handler functions</span>928<span class="k">def</span><span class="w"> </span><span class="nf">start_element</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">attrs</span><span class="p">):</span>929    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Start element:&#39;</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">attrs</span><span class="p">)</span>930<span class="k">def</span><span class="w"> </span><span class="nf">end_element</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>931    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;End element:&#39;</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>932<span class="k">def</span><span class="w"> </span><span class="nf">char_data</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>933    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Character data:&#39;</span><span class="p">,</span> <span class="nb">repr</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>934 935<span class="n">p</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">parsers</span><span class="o">.</span><span class="n">expat</span><span class="o">.</span><span class="n">ParserCreate</span><span class="p">()</span>936 937<span class="n">p</span><span class="o">.</span><span class="n">StartElementHandler</span> <span class="o">=</span> <span class="n">start_element</span>938<span class="n">p</span><span class="o">.</span><span class="n">EndElementHandler</span> <span class="o">=</span> <span class="n">end_element</span>939<span class="n">p</span><span class="o">.</span><span class="n">CharacterDataHandler</span> <span class="o">=</span> <span class="n">char_data</span>940 941<span class="n">p</span><span class="o">.</span><span class="n">Parse</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot;?&gt;</span>942<span class="s2">&lt;parent id=&quot;top&quot;&gt;&lt;child1 name=&quot;paul&quot;&gt;Text goes here&lt;/child1&gt;</span>943<span class="s2">&lt;child2 name=&quot;fred&quot;&gt;More text&lt;/child2&gt;</span>944<span class="s2">&lt;/parent&gt;&quot;&quot;&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>945</pre></div>946</div>947<p>The output from this program is:</p>948<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Start</span> <span class="n">element</span><span class="p">:</span> <span class="n">parent</span> <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="s1">&#39;top&#39;</span><span class="p">}</span>949<span class="n">Start</span> <span class="n">element</span><span class="p">:</span> <span class="n">child1</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;paul&#39;</span><span class="p">}</span>950<span class="n">Character</span> <span class="n">data</span><span class="p">:</span> <span class="s1">&#39;Text goes here&#39;</span>951<span class="n">End</span> <span class="n">element</span><span class="p">:</span> <span class="n">child1</span>952<span class="n">Character</span> <span class="n">data</span><span class="p">:</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>953<span class="n">Start</span> <span class="n">element</span><span class="p">:</span> <span class="n">child2</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;fred&#39;</span><span class="p">}</span>954<span class="n">Character</span> <span class="n">data</span><span class="p">:</span> <span class="s1">&#39;More text&#39;</span>955<span class="n">End</span> <span class="n">element</span><span class="p">:</span> <span class="n">child2</span>956<span class="n">Character</span> <span class="n">data</span><span class="p">:</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>957<span class="n">End</span> <span class="n">element</span><span class="p">:</span> <span class="n">parent</span>958</pre></div>959</div>960</section>961<section id="module-xml.parsers.expat.model">962<span id="content-model-descriptions"></span><span id="expat-content-models"></span><h2>Content Model Descriptions<a class="headerlink" href="#module-xml.parsers.expat.model" title="Link to this heading">¶</a></h2>963<p>Content models are described using nested tuples.  Each tuple contains four964values: the type, the quantifier, the name, and a tuple of children.  Children965are simply additional content model descriptions.</p>966<p>The values of the first two fields are constants defined in the967<code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.parsers.expat.model</span></code> module.  These constants can be collected in two968groups: the model type group and the quantifier group.</p>969<p>The constants in the model type group are:</p>970<dl class="py data">971<dt class="sig sig-object py">972<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CTYPE_ANY</span></span></dt>973<dd><p>The element named by the model name was declared to have a content model of974<code class="docutils literal notranslate"><span class="pre">ANY</span></code>.</p>975</dd></dl>976 977<dl class="py data">978<dt class="sig sig-object py">979<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CTYPE_CHOICE</span></span></dt>980<dd><p>The named element allows a choice from a number of options; this is used for981content models such as <code class="docutils literal notranslate"><span class="pre">(A</span> <span class="pre">|</span> <span class="pre">B</span> <span class="pre">|</span> <span class="pre">C)</span></code>.</p>982</dd></dl>983 984<dl class="py data">985<dt class="sig sig-object py">986<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CTYPE_EMPTY</span></span></dt>987<dd><p>Elements which are declared to be <code class="docutils literal notranslate"><span class="pre">EMPTY</span></code> have this model type.</p>988</dd></dl>989 990<dl class="py data">991<dt class="sig sig-object py">992<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CTYPE_MIXED</span></span></dt>993<dd></dd></dl>994 995<dl class="py data">996<dt class="sig sig-object py">997<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CTYPE_NAME</span></span></dt>998<dd></dd></dl>999 1000<dl class="py data">1001<dt class="sig sig-object py">1002<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CTYPE_SEQ</span></span></dt>1003<dd><p>Models which represent a series of models which follow one after the other are1004indicated with this model type.  This is used for models such as <code class="docutils literal notranslate"><span class="pre">(A,</span> <span class="pre">B,</span> <span class="pre">C)</span></code>.</p>1005</dd></dl>1006 1007<p>The constants in the quantifier group are:</p>1008<dl class="py data">1009<dt class="sig sig-object py">1010<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CQUANT_NONE</span></span></dt>1011<dd><p>No modifier is given, so it can appear exactly once, as for <code class="docutils literal notranslate"><span class="pre">A</span></code>.</p>1012</dd></dl>1013 1014<dl class="py data">1015<dt class="sig sig-object py">1016<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CQUANT_OPT</span></span></dt>1017<dd><p>The model is optional: it can appear once or not at all, as for <code class="docutils literal notranslate"><span class="pre">A?</span></code>.</p>1018</dd></dl>1019 1020<dl class="py data">1021<dt class="sig sig-object py">1022<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CQUANT_PLUS</span></span></dt>1023<dd><p>The model must occur one or more times (like <code class="docutils literal notranslate"><span class="pre">A+</span></code>).</p>1024</dd></dl>1025 1026<dl class="py data">1027<dt class="sig sig-object py">1028<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.model.</span></span><span class="sig-name descname"><span class="pre">XML_CQUANT_REP</span></span></dt>1029<dd><p>The model must occur zero or more times, as for <code class="docutils literal notranslate"><span class="pre">A*</span></code>.</p>1030</dd></dl>1031 1032</section>1033<section id="module-xml.parsers.expat.errors">1034<span id="expat-error-constants"></span><span id="expat-errors"></span><h2>Expat error constants<a class="headerlink" href="#module-xml.parsers.expat.errors" title="Link to this heading">¶</a></h2>1035<p>The following constants are provided in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.parsers.expat.errors</span></code>1036module.  These constants are useful in interpreting some of the attributes of1037the <code class="xref py py-exc docutils literal notranslate"><span class="pre">ExpatError</span></code> exception objects raised when an error has occurred.1038Since for backwards compatibility reasons, the constants’ value is the error1039<em>message</em> and not the numeric error <em>code</em>, you do this by comparing its1040<a class="reference internal" href="code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-attr docutils literal notranslate"><span class="pre">code</span></code></a> attribute with1041<code class="samp docutils literal notranslate"><span class="pre">errors.codes[errors.XML_ERROR_</span><em><span class="pre">CONSTANT_NAME</span></em><span class="pre">]</span></code>.</p>1042<p>The <code class="docutils literal notranslate"><span class="pre">errors</span></code> module has the following attributes:</p>1043<dl class="py data">1044<dt class="sig sig-object py" id="xml.parsers.expat.errors.codes">1045<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">codes</span></span><a class="headerlink" href="#xml.parsers.expat.errors.codes" title="Link to this definition">¶</a></dt>1046<dd><p>A dictionary mapping string descriptions to their error codes.</p>1047<div class="versionadded">1048<p><span class="versionmodified added">Added in version 3.2.</span></p>1049</div>1050</dd></dl>1051 1052<dl class="py data">1053<dt class="sig sig-object py" id="xml.parsers.expat.errors.messages">1054<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">messages</span></span><a class="headerlink" href="#xml.parsers.expat.errors.messages" title="Link to this definition">¶</a></dt>1055<dd><p>A dictionary mapping numeric error codes to their string descriptions.</p>1056<div class="versionadded">1057<p><span class="versionmodified added">Added in version 3.2.</span></p>1058</div>1059</dd></dl>1060 1061<dl class="py data">1062<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_ASYNC_ENTITY">1063<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_ASYNC_ENTITY</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_ASYNC_ENTITY" title="Link to this definition">¶</a></dt>1064<dd></dd></dl>1065 1066<dl class="py data">1067<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF">1068<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF" title="Link to this definition">¶</a></dt>1069<dd><p>An entity reference in an attribute value referred to an external entity instead1070of an internal entity.</p>1071</dd></dl>1072 1073<dl class="py data">1074<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_BAD_CHAR_REF">1075<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_BAD_CHAR_REF</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_BAD_CHAR_REF" title="Link to this definition">¶</a></dt>1076<dd><p>A character reference referred to a character which is illegal in XML (for1077example, character <code class="docutils literal notranslate"><span class="pre">0</span></code>, or ‘<code class="docutils literal notranslate"><span class="pre">&amp;#0;</span></code>’).</p>1078</dd></dl>1079 1080<dl class="py data">1081<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_BINARY_ENTITY_REF">1082<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_BINARY_ENTITY_REF</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_BINARY_ENTITY_REF" title="Link to this definition">¶</a></dt>1083<dd><p>An entity reference referred to an entity which was declared with a notation, so1084cannot be parsed.</p>1085</dd></dl>1086 1087<dl class="py data">1088<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_DUPLICATE_ATTRIBUTE">1089<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_DUPLICATE_ATTRIBUTE</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_DUPLICATE_ATTRIBUTE" title="Link to this definition">¶</a></dt>1090<dd><p>An attribute was used more than once in a start tag.</p>1091</dd></dl>1092 1093<dl class="py data">1094<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_INCORRECT_ENCODING">1095<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_INCORRECT_ENCODING</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_INCORRECT_ENCODING" title="Link to this definition">¶</a></dt>1096<dd></dd></dl>1097 1098<dl class="py data">1099<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_INVALID_TOKEN">1100<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_INVALID_TOKEN</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_INVALID_TOKEN" title="Link to this definition">¶</a></dt>1101<dd><p>Raised when an input byte could not properly be assigned to a character; for1102example, a NUL byte (value <code class="docutils literal notranslate"><span class="pre">0</span></code>) in a UTF-8 input stream.</p>1103</dd></dl>1104 1105<dl class="py data">1106<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_JUNK_AFTER_DOC_ELEMENT">1107<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_JUNK_AFTER_DOC_ELEMENT</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_JUNK_AFTER_DOC_ELEMENT" title="Link to this definition">¶</a></dt>1108<dd><p>Something other than whitespace occurred after the document element.</p>1109</dd></dl>1110 1111<dl class="py data">1112<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_MISPLACED_XML_PI">1113<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_MISPLACED_XML_PI</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_MISPLACED_XML_PI" title="Link to this definition">¶</a></dt>1114<dd><p>An XML declaration was found somewhere other than the start of the input data.</p>1115</dd></dl>1116 1117<dl class="py data">1118<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS">1119<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_NO_ELEMENTS</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS" title="Link to this definition">¶</a></dt>1120<dd><p>The document contains no elements (XML requires all documents to contain exactly1121one top-level element)..</p>1122</dd></dl>1123 1124<dl class="py data">1125<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_NO_MEMORY">1126<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_NO_MEMORY</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_NO_MEMORY" title="Link to this definition">¶</a></dt>1127<dd><p>Expat was not able to allocate memory internally.</p>1128</dd></dl>1129 1130<dl class="py data">1131<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_PARAM_ENTITY_REF">1132<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_PARAM_ENTITY_REF</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_PARAM_ENTITY_REF" title="Link to this definition">¶</a></dt>1133<dd><p>A parameter entity reference was found where it was not allowed.</p>1134</dd></dl>1135 1136<dl class="py data">1137<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_PARTIAL_CHAR">1138<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_PARTIAL_CHAR</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_PARTIAL_CHAR" title="Link to this definition">¶</a></dt>1139<dd><p>An incomplete character was found in the input.</p>1140</dd></dl>1141 1142<dl class="py data">1143<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_RECURSIVE_ENTITY_REF">1144<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_RECURSIVE_ENTITY_REF</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_RECURSIVE_ENTITY_REF" title="Link to this definition">¶</a></dt>1145<dd><p>An entity reference contained another reference to the same entity; possibly via1146a different name, and possibly indirectly.</p>1147</dd></dl>1148 1149<dl class="py data">1150<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_SYNTAX">1151<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_SYNTAX</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_SYNTAX" title="Link to this definition">¶</a></dt>1152<dd><p>Some unspecified syntax error was encountered.</p>1153</dd></dl>1154 1155<dl class="py data">1156<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_TAG_MISMATCH">1157<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_TAG_MISMATCH</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_TAG_MISMATCH" title="Link to this definition">¶</a></dt>1158<dd><p>An end tag did not match the innermost open start tag.</p>1159</dd></dl>1160 1161<dl class="py data">1162<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_UNCLOSED_TOKEN">1163<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_UNCLOSED_TOKEN</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_UNCLOSED_TOKEN" title="Link to this definition">¶</a></dt>1164<dd><p>Some token (such as a start tag) was not closed before the end of the stream or1165the next token was encountered.</p>1166</dd></dl>1167 1168<dl class="py data">1169<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_UNDEFINED_ENTITY">1170<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_UNDEFINED_ENTITY</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_UNDEFINED_ENTITY" title="Link to this definition">¶</a></dt>1171<dd><p>A reference was made to an entity which was not defined.</p>1172</dd></dl>1173 1174<dl class="py data">1175<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_UNKNOWN_ENCODING">1176<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_UNKNOWN_ENCODING</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_UNKNOWN_ENCODING" title="Link to this definition">¶</a></dt>1177<dd><p>The document encoding is not supported by Expat.</p>1178</dd></dl>1179 1180<dl class="py data">1181<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_UNCLOSED_CDATA_SECTION">1182<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_UNCLOSED_CDATA_SECTION</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_UNCLOSED_CDATA_SECTION" title="Link to this definition">¶</a></dt>1183<dd><p>A CDATA marked section was not closed.</p>1184</dd></dl>1185 1186<dl class="py data">1187<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_EXTERNAL_ENTITY_HANDLING">1188<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_EXTERNAL_ENTITY_HANDLING</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_EXTERNAL_ENTITY_HANDLING" title="Link to this definition">¶</a></dt>1189<dd></dd></dl>1190 1191<dl class="py data">1192<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_NOT_STANDALONE">1193<span class="sig-prename descclassname"><span class="pre">xml.parsers.expat.errors.</span></span><span class="sig-name descname"><span class="pre">XML_ERROR_NOT_STANDALONE</span></span><a class="headerlink" href="#xml.parsers.expat.errors.XML_ERROR_NOT_STANDALONE" title="Link to this definition">¶</a></dt>1194<dd><p>The parser determined that the document was not “standalone” though it declared1195itself to be in the XML declaration, and the <code class="xref py py-attr docutils literal notranslate"><span class="pre">NotStandaloneHandler</span></code> was1196set and returned <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>1197</dd></dl>1198 1199<dl class="py data">1200<dt class="sig sig-object py" id="xml.parsers.expat.errors.XML_ERROR_UNEXPECTED_STATE">

Showing the first 1,200 of 1504 lines. Download the file for the rest.