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

488 lines
34KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="xml.sax — Support for SAX2 parsers" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/xml.sax.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/xml/sax/__init__.py The xml.sax package provides a number of modules which implement the Simple API for XML (SAX) interface for Python. The package itself provides the SAX exceptio..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/xml/sax/__init__.py The xml.sax package provides a number of modules which implement the Simple API for XML (SAX) interface for Python. The package itself provides the SAX exceptio..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>xml.sax — Support for SAX2 parsers &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="xml.sax.handler — Base classes for SAX handlers" href="xml.sax.handler.html" />
  33. <link rel="prev" title="xml.dom.pulldom — Support for building partial DOM trees" href="xml.dom.pulldom.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/xml.sax.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a><ul>
  86. <li><a class="reference internal" href="#saxexception-objects">SAXException Objects</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div>
  92. <h4>Previous topic</h4>
  93. <p class="topless"><a href="xml.dom.pulldom.html"
  94. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> — Support for building partial DOM trees</a></p>
  95. </div>
  96. <div>
  97. <h4>Next topic</h4>
  98. <p class="topless"><a href="xml.sax.handler.html"
  99. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> — Base classes for SAX handlers</a></p>
  100. </div>
  101. <div role="note" aria-label="source link">
  102. <h3>This Page</h3>
  103. <ul class="this-page-menu">
  104. <li><a href="../bugs.html">Report a Bug</a></li>
  105. <li>
  106. <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.sax.rst"
  107. rel="nofollow">Show Source
  108. </a>
  109. </li>
  110. </ul>
  111. </div>
  112. </nav>
  113. </div>
  114. </div>
  115. <div class="related" role="navigation" aria-label="related navigation">
  116. <h3>Navigation</h3>
  117. <ul>
  118. <li class="right" style="margin-right: 10px">
  119. <a href="../genindex.html" title="General Index"
  120. accesskey="I">index</a></li>
  121. <li class="right" >
  122. <a href="../py-modindex.html" title="Python Module Index"
  123. >modules</a> |</li>
  124. <li class="right" >
  125. <a href="xml.sax.handler.html" title="xml.sax.handler — Base classes for SAX handlers"
  126. accesskey="N">next</a> |</li>
  127. <li class="right" >
  128. <a href="xml.dom.pulldom.html" title="xml.dom.pulldom — Support for building partial DOM trees"
  129. accesskey="P">previous</a> |</li>
  130. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  131. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  132. <li class="switchers">
  133. <div class="language_switcher_placeholder"></div>
  134. <div class="version_switcher_placeholder"></div>
  135. </li>
  136. <li>
  137. </li>
  138. <li id="cpython-language-and-version">
  139. <a href="../index.html">3.12.3 Documentation</a> &#187;
  140. </li>
  141. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  142. <li class="nav-item nav-item-2"><a href="markup.html" accesskey="U">Structured Markup Processing Tools</a> &#187;</li>
  143. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a></li>
  144. <li class="right">
  145. <div class="inline-search" role="search">
  146. <form class="inline-search" action="../search.html" method="get">
  147. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  148. <input type="submit" value="Go" />
  149. </form>
  150. </div>
  151. |
  152. </li>
  153. <li class="right">
  154. <label class="theme-selector-label">
  155. Theme
  156. <select class="theme-selector" oninput="activateTheme(this.value)">
  157. <option value="auto" selected>Auto</option>
  158. <option value="light">Light</option>
  159. <option value="dark">Dark</option>
  160. </select>
  161. </label> |</li>
  162. </ul>
  163. </div>
  164. <div class="document">
  165. <div class="documentwrapper">
  166. <div class="bodywrapper">
  167. <div class="body" role="main">
  168. <section id="module-xml.sax">
  169. <span id="xml-sax-support-for-sax2-parsers"></span><h1><a class="reference internal" href="#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> — Support for SAX2 parsers<a class="headerlink" href="#module-xml.sax" title="Link to this heading">¶</a></h1>
  170. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/xml/sax/__init__.py">Lib/xml/sax/__init__.py</a></p>
  171. <hr class="docutils" />
  172. <p>The <a class="reference internal" href="#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> package provides a number of modules which implement the
  173. Simple API for XML (SAX) interface for Python. The package itself provides the
  174. SAX exceptions and the convenience functions which will be most used by users of
  175. the SAX API.</p>
  176. <div class="admonition warning">
  177. <p class="admonition-title">Warning</p>
  178. <p>The <a class="reference internal" href="#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> module is not secure against maliciously
  179. constructed data. If you need to parse untrusted or unauthenticated data see
  180. <a class="reference internal" href="xml.html#xml-vulnerabilities"><span class="std std-ref">XML vulnerabilities</span></a>.</p>
  181. </div>
  182. <div class="versionchanged">
  183. <p><span class="versionmodified changed">Changed in version 3.7.1: </span>The SAX parser no longer processes general external entities by default
  184. to increase security. Before, the parser created network connections
  185. to fetch remote files or loaded local files from the file
  186. system for DTD and entities. The feature can be enabled again with method
  187. <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader.setFeature" title="xml.sax.xmlreader.XMLReader.setFeature"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setFeature()</span></code></a> on the parser object
  188. and argument <a class="reference internal" href="xml.sax.handler.html#xml.sax.handler.feature_external_ges" title="xml.sax.handler.feature_external_ges"><code class="xref py py-data docutils literal notranslate"><span class="pre">feature_external_ges</span></code></a>.</p>
  189. </div>
  190. <p>The convenience functions are:</p>
  191. <dl class="py function">
  192. <dt class="sig sig-object py" id="xml.sax.make_parser">
  193. <span class="sig-prename descclassname"><span class="pre">xml.sax.</span></span><span class="sig-name descname"><span class="pre">make_parser</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">parser_list</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">[]</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.make_parser" title="Link to this definition">¶</a></dt>
  194. <dd><p>Create and return a SAX <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader" title="xml.sax.xmlreader.XMLReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code></a> object. The
  195. first parser found will
  196. be used. If <em>parser_list</em> is provided, it must be an iterable of strings which
  197. name modules that have a function named <code class="xref py py-func docutils literal notranslate"><span class="pre">create_parser()</span></code>. Modules listed
  198. in <em>parser_list</em> will be used before modules in the default list of parsers.</p>
  199. <div class="versionchanged">
  200. <p><span class="versionmodified changed">Changed in version 3.8: </span>The <em>parser_list</em> argument can be any iterable, not just a list.</p>
  201. </div>
  202. </dd></dl>
  203. <dl class="py function">
  204. <dt class="sig sig-object py" id="xml.sax.parse">
  205. <span class="sig-prename descclassname"><span class="pre">xml.sax.</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">filename_or_stream</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">handler</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">error_handler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">handler.ErrorHandler()</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.parse" title="Link to this definition">¶</a></dt>
  206. <dd><p>Create a SAX parser and use it to parse a document. The document, passed in as
  207. <em>filename_or_stream</em>, can be a filename or a file object. The <em>handler</em>
  208. parameter needs to be a SAX <a class="reference internal" href="xml.sax.handler.html#xml.sax.handler.ContentHandler" title="xml.sax.handler.ContentHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">ContentHandler</span></code></a> instance. If
  209. <em>error_handler</em> is given, it must be a SAX <a class="reference internal" href="xml.sax.handler.html#xml.sax.handler.ErrorHandler" title="xml.sax.handler.ErrorHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">ErrorHandler</span></code></a>
  210. instance; if
  211. omitted, <a class="reference internal" href="#xml.sax.SAXParseException" title="xml.sax.SAXParseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SAXParseException</span></code></a> will be raised on all errors. There is no
  212. return value; all work must be done by the <em>handler</em> passed in.</p>
  213. </dd></dl>
  214. <dl class="py function">
  215. <dt class="sig sig-object py" id="xml.sax.parseString">
  216. <span class="sig-prename descclassname"><span class="pre">xml.sax.</span></span><span class="sig-name descname"><span class="pre">parseString</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">handler</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">error_handler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">handler.ErrorHandler()</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.parseString" title="Link to this definition">¶</a></dt>
  217. <dd><p>Similar to <a class="reference internal" href="#xml.sax.parse" title="xml.sax.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse()</span></code></a>, but parses from a buffer <em>string</em> received as a
  218. parameter. <em>string</em> must be a <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> instance or a
  219. <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>.</p>
  220. <div class="versionchanged">
  221. <p><span class="versionmodified changed">Changed in version 3.5: </span>Added support of <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> instances.</p>
  222. </div>
  223. </dd></dl>
  224. <p>A typical SAX application uses three kinds of objects: readers, handlers and
  225. input sources. “Reader” in this context is another term for parser, i.e. some
  226. piece of code that reads the bytes or characters from the input source, and
  227. produces a sequence of events. The events then get distributed to the handler
  228. objects, i.e. the reader invokes a method on the handler. A SAX application
  229. must therefore obtain a reader object, create or open the input sources, create
  230. the handlers, and connect these objects all together. As the final step of
  231. preparation, the reader is called to parse the input. During parsing, methods on
  232. the handler objects are called based on structural and syntactic events from the
  233. input data.</p>
  234. <p>For these objects, only the interfaces are relevant; they are normally not
  235. instantiated by the application itself. Since Python does not have an explicit
  236. notion of interface, they are formally introduced as classes, but applications
  237. may use implementations which do not inherit from the provided classes. The
  238. <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.InputSource" title="xml.sax.xmlreader.InputSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">InputSource</span></code></a>, <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.Locator" title="xml.sax.xmlreader.Locator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Locator</span></code></a>,
  239. <code class="xref py py-class docutils literal notranslate"><span class="pre">Attributes</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">AttributesNS</span></code>,
  240. and <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader" title="xml.sax.xmlreader.XMLReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code></a> interfaces are defined in the
  241. module <a class="reference internal" href="xml.sax.reader.html#module-xml.sax.xmlreader" title="xml.sax.xmlreader: Interface which SAX-compliant XML parsers must implement."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.xmlreader</span></code></a>. The handler interfaces are defined in
  242. <a class="reference internal" href="xml.sax.handler.html#module-xml.sax.handler" title="xml.sax.handler: Base classes for SAX event handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code></a>. For convenience,
  243. <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.InputSource" title="xml.sax.xmlreader.InputSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">InputSource</span></code></a> (which is often
  244. instantiated directly) and the handler classes are also available from
  245. <a class="reference internal" href="#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a>. These interfaces are described below.</p>
  246. <p>In addition to these classes, <a class="reference internal" href="#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> provides the following exception
  247. classes.</p>
  248. <dl class="py exception">
  249. <dt class="sig sig-object py" id="xml.sax.SAXException">
  250. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.</span></span><span class="sig-name descname"><span class="pre">SAXException</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exception</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.sax.SAXException" title="Link to this definition">¶</a></dt>
  251. <dd><p>Encapsulate an XML error or warning. This class can contain basic error or
  252. warning information from either the XML parser or the application: it can be
  253. subclassed to provide additional functionality or to add localization. Note
  254. that although the handlers defined in the
  255. <a class="reference internal" href="xml.sax.handler.html#xml.sax.handler.ErrorHandler" title="xml.sax.handler.ErrorHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">ErrorHandler</span></code></a> interface
  256. receive instances of this exception, it is not required to actually raise the
  257. exception — it is also useful as a container for information.</p>
  258. <p>When instantiated, <em>msg</em> should be a human-readable description of the error.
  259. The optional <em>exception</em> parameter, if given, should be <code class="docutils literal notranslate"><span class="pre">None</span></code> or an exception
  260. that was caught by the parsing code and is being passed along as information.</p>
  261. <p>This is the base class for the other SAX exception classes.</p>
  262. </dd></dl>
  263. <dl class="py exception">
  264. <dt class="sig sig-object py" id="xml.sax.SAXParseException">
  265. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.</span></span><span class="sig-name descname"><span class="pre">SAXParseException</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exception</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locator</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.SAXParseException" title="Link to this definition">¶</a></dt>
  266. <dd><p>Subclass of <a class="reference internal" href="#xml.sax.SAXException" title="xml.sax.SAXException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SAXException</span></code></a> raised on parse errors. Instances of this
  267. class are passed to the methods of the SAX
  268. <a class="reference internal" href="xml.sax.handler.html#xml.sax.handler.ErrorHandler" title="xml.sax.handler.ErrorHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">ErrorHandler</span></code></a> interface to provide information
  269. about the parse error. This class supports the SAX
  270. <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.Locator" title="xml.sax.xmlreader.Locator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Locator</span></code></a> interface as well as the
  271. <a class="reference internal" href="#xml.sax.SAXException" title="xml.sax.SAXException"><code class="xref py py-class docutils literal notranslate"><span class="pre">SAXException</span></code></a> interface.</p>
  272. </dd></dl>
  273. <dl class="py exception">
  274. <dt class="sig sig-object py" id="xml.sax.SAXNotRecognizedException">
  275. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.</span></span><span class="sig-name descname"><span class="pre">SAXNotRecognizedException</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exception</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.sax.SAXNotRecognizedException" title="Link to this definition">¶</a></dt>
  276. <dd><p>Subclass of <a class="reference internal" href="#xml.sax.SAXException" title="xml.sax.SAXException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SAXException</span></code></a> raised when a SAX
  277. <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader" title="xml.sax.xmlreader.XMLReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code></a> is
  278. confronted with an unrecognized feature or property. SAX applications and
  279. extensions may use this class for similar purposes.</p>
  280. </dd></dl>
  281. <dl class="py exception">
  282. <dt class="sig sig-object py" id="xml.sax.SAXNotSupportedException">
  283. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.sax.</span></span><span class="sig-name descname"><span class="pre">SAXNotSupportedException</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exception</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.sax.SAXNotSupportedException" title="Link to this definition">¶</a></dt>
  284. <dd><p>Subclass of <a class="reference internal" href="#xml.sax.SAXException" title="xml.sax.SAXException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SAXException</span></code></a> raised when a SAX
  285. <a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader" title="xml.sax.xmlreader.XMLReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code></a> is asked to
  286. enable a feature that is not supported, or to set a property to a value that the
  287. implementation does not support. SAX applications and extensions may use this
  288. class for similar purposes.</p>
  289. </dd></dl>
  290. <div class="admonition seealso">
  291. <p class="admonition-title">See also</p>
  292. <dl class="simple">
  293. <dt><a class="reference external" href="http://www.saxproject.org/">SAX: The Simple API for XML</a></dt><dd><p>This site is the focal point for the definition of the SAX API. It provides a
  294. Java implementation and online documentation. Links to implementations and
  295. historical information are also available.</p>
  296. </dd>
  297. <dt>Module <a class="reference internal" href="xml.sax.handler.html#module-xml.sax.handler" title="xml.sax.handler: Base classes for SAX event handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code></a></dt><dd><p>Definitions of the interfaces for application-provided objects.</p>
  298. </dd>
  299. <dt>Module <a class="reference internal" href="xml.sax.utils.html#module-xml.sax.saxutils" title="xml.sax.saxutils: Convenience functions and classes for use with SAX."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.saxutils</span></code></a></dt><dd><p>Convenience functions for use in SAX applications.</p>
  300. </dd>
  301. <dt>Module <a class="reference internal" href="xml.sax.reader.html#module-xml.sax.xmlreader" title="xml.sax.xmlreader: Interface which SAX-compliant XML parsers must implement."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.xmlreader</span></code></a></dt><dd><p>Definitions of the interfaces for parser-provided objects.</p>
  302. </dd>
  303. </dl>
  304. </div>
  305. <section id="saxexception-objects">
  306. <span id="sax-exception-objects"></span><h2>SAXException Objects<a class="headerlink" href="#saxexception-objects" title="Link to this heading">¶</a></h2>
  307. <p>The <a class="reference internal" href="#xml.sax.SAXException" title="xml.sax.SAXException"><code class="xref py py-class docutils literal notranslate"><span class="pre">SAXException</span></code></a> exception class supports the following methods:</p>
  308. <dl class="py method">
  309. <dt class="sig sig-object py" id="xml.sax.SAXException.getMessage">
  310. <span class="sig-prename descclassname"><span class="pre">SAXException.</span></span><span class="sig-name descname"><span class="pre">getMessage</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.SAXException.getMessage" title="Link to this definition">¶</a></dt>
  311. <dd><p>Return a human-readable message describing the error condition.</p>
  312. </dd></dl>
  313. <dl class="py method">
  314. <dt class="sig sig-object py" id="xml.sax.SAXException.getException">
  315. <span class="sig-prename descclassname"><span class="pre">SAXException.</span></span><span class="sig-name descname"><span class="pre">getException</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.sax.SAXException.getException" title="Link to this definition">¶</a></dt>
  316. <dd><p>Return an encapsulated exception object, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  317. </dd></dl>
  318. </section>
  319. </section>
  320. <div class="clearer"></div>
  321. </div>
  322. </div>
  323. </div>
  324. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  325. <div class="sphinxsidebarwrapper">
  326. <div>
  327. <h3><a href="../contents.html">Table of Contents</a></h3>
  328. <ul>
  329. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a><ul>
  330. <li><a class="reference internal" href="#saxexception-objects">SAXException Objects</a></li>
  331. </ul>
  332. </li>
  333. </ul>
  334. </div>
  335. <div>
  336. <h4>Previous topic</h4>
  337. <p class="topless"><a href="xml.dom.pulldom.html"
  338. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> — Support for building partial DOM trees</a></p>
  339. </div>
  340. <div>
  341. <h4>Next topic</h4>
  342. <p class="topless"><a href="xml.sax.handler.html"
  343. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code> — Base classes for SAX handlers</a></p>
  344. </div>
  345. <div role="note" aria-label="source link">
  346. <h3>This Page</h3>
  347. <ul class="this-page-menu">
  348. <li><a href="../bugs.html">Report a Bug</a></li>
  349. <li>
  350. <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.sax.rst"
  351. rel="nofollow">Show Source
  352. </a>
  353. </li>
  354. </ul>
  355. </div>
  356. </div>
  357. <div id="sidebarbutton" title="Collapse sidebar">
  358. <span>«</span>
  359. </div>
  360. </div>
  361. <div class="clearer"></div>
  362. </div>
  363. <div class="related" role="navigation" aria-label="related navigation">
  364. <h3>Navigation</h3>
  365. <ul>
  366. <li class="right" style="margin-right: 10px">
  367. <a href="../genindex.html" title="General Index"
  368. >index</a></li>
  369. <li class="right" >
  370. <a href="../py-modindex.html" title="Python Module Index"
  371. >modules</a> |</li>
  372. <li class="right" >
  373. <a href="xml.sax.handler.html" title="xml.sax.handler — Base classes for SAX handlers"
  374. >next</a> |</li>
  375. <li class="right" >
  376. <a href="xml.dom.pulldom.html" title="xml.dom.pulldom — Support for building partial DOM trees"
  377. >previous</a> |</li>
  378. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  379. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  380. <li class="switchers">
  381. <div class="language_switcher_placeholder"></div>
  382. <div class="version_switcher_placeholder"></div>
  383. </li>
  384. <li>
  385. </li>
  386. <li id="cpython-language-and-version">
  387. <a href="../index.html">3.12.3 Documentation</a> &#187;
  388. </li>
  389. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  390. <li class="nav-item nav-item-2"><a href="markup.html" >Structured Markup Processing Tools</a> &#187;</li>
  391. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a></li>
  392. <li class="right">
  393. <div class="inline-search" role="search">
  394. <form class="inline-search" action="../search.html" method="get">
  395. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  396. <input type="submit" value="Go" />
  397. </form>
  398. </div>
  399. |
  400. </li>
  401. <li class="right">
  402. <label class="theme-selector-label">
  403. Theme
  404. <select class="theme-selector" oninput="activateTheme(this.value)">
  405. <option value="auto" selected>Auto</option>
  406. <option value="light">Light</option>
  407. <option value="dark">Dark</option>
  408. </select>
  409. </label> |</li>
  410. </ul>
  411. </div>
  412. <div class="footer">
  413. &copy;
  414. <a href="../copyright.html">
  415. Copyright
  416. </a>
  417. 2001-2024, Python Software Foundation.
  418. <br />
  419. This page is licensed under the Python Software Foundation License Version 2.
  420. <br />
  421. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  422. <br />
  423. See <a href="/license.html">History and License</a> for more information.<br />
  424. <br />
  425. The Python Software Foundation is a non-profit corporation.
  426. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  427. <br />
  428. <br />
  429. Last updated on Apr 09, 2024 (13:47 UTC).
  430. <a href="/bugs.html">Found a bug</a>?
  431. <br />
  432. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  433. </div>
  434. </body>
  435. </html>
上海开阖软件有限公司 沪ICP备12045867号-1