gooderp18绿色标准版
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1435 rindas
116KB

  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.dom — The Document Object Model API" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/xml.dom.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/xml/dom/__init__.py The Document Object Model, or “DOM,” is a cross-language API from the World Wide Web Consortium (W3C) for accessing and modifying XML documents. A DOM implement..." />
  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/dom/__init__.py The Document Object Model, or “DOM,” is a cross-language API from the World Wide Web Consortium (W3C) for accessing and modifying XML documents. A DOM implement..." />
  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.dom — The Document Object Model API &#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.dom.minidom — Minimal DOM implementation" href="xml.dom.minidom.html" />
  33. <link rel="prev" title="xml.etree.ElementTree — The ElementTree XML API" href="xml.etree.elementtree.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/xml.dom.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.dom</span></code> — The Document Object Model API</a><ul>
  86. <li><a class="reference internal" href="#module-contents">Module Contents</a></li>
  87. <li><a class="reference internal" href="#objects-in-the-dom">Objects in the DOM</a><ul>
  88. <li><a class="reference internal" href="#domimplementation-objects">DOMImplementation Objects</a></li>
  89. <li><a class="reference internal" href="#node-objects">Node Objects</a></li>
  90. <li><a class="reference internal" href="#nodelist-objects">NodeList Objects</a></li>
  91. <li><a class="reference internal" href="#documenttype-objects">DocumentType Objects</a></li>
  92. <li><a class="reference internal" href="#document-objects">Document Objects</a></li>
  93. <li><a class="reference internal" href="#element-objects">Element Objects</a></li>
  94. <li><a class="reference internal" href="#attr-objects">Attr Objects</a></li>
  95. <li><a class="reference internal" href="#namednodemap-objects">NamedNodeMap Objects</a></li>
  96. <li><a class="reference internal" href="#comment-objects">Comment Objects</a></li>
  97. <li><a class="reference internal" href="#text-and-cdatasection-objects">Text and CDATASection Objects</a></li>
  98. <li><a class="reference internal" href="#processinginstruction-objects">ProcessingInstruction Objects</a></li>
  99. <li><a class="reference internal" href="#exceptions">Exceptions</a></li>
  100. </ul>
  101. </li>
  102. <li><a class="reference internal" href="#conformance">Conformance</a><ul>
  103. <li><a class="reference internal" href="#type-mapping">Type Mapping</a></li>
  104. <li><a class="reference internal" href="#accessor-methods">Accessor Methods</a></li>
  105. </ul>
  106. </li>
  107. </ul>
  108. </li>
  109. </ul>
  110. </div>
  111. <div>
  112. <h4>Previous topic</h4>
  113. <p class="topless"><a href="xml.etree.elementtree.html"
  114. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code> — The ElementTree XML API</a></p>
  115. </div>
  116. <div>
  117. <h4>Next topic</h4>
  118. <p class="topless"><a href="xml.dom.minidom.html"
  119. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code> — Minimal DOM implementation</a></p>
  120. </div>
  121. <div role="note" aria-label="source link">
  122. <h3>This Page</h3>
  123. <ul class="this-page-menu">
  124. <li><a href="../bugs.html">Report a Bug</a></li>
  125. <li>
  126. <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.dom.rst"
  127. rel="nofollow">Show Source
  128. </a>
  129. </li>
  130. </ul>
  131. </div>
  132. </nav>
  133. </div>
  134. </div>
  135. <div class="related" role="navigation" aria-label="related navigation">
  136. <h3>Navigation</h3>
  137. <ul>
  138. <li class="right" style="margin-right: 10px">
  139. <a href="../genindex.html" title="General Index"
  140. accesskey="I">index</a></li>
  141. <li class="right" >
  142. <a href="../py-modindex.html" title="Python Module Index"
  143. >modules</a> |</li>
  144. <li class="right" >
  145. <a href="xml.dom.minidom.html" title="xml.dom.minidom — Minimal DOM implementation"
  146. accesskey="N">next</a> |</li>
  147. <li class="right" >
  148. <a href="xml.etree.elementtree.html" title="xml.etree.ElementTree — The ElementTree XML API"
  149. accesskey="P">previous</a> |</li>
  150. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  151. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  152. <li class="switchers">
  153. <div class="language_switcher_placeholder"></div>
  154. <div class="version_switcher_placeholder"></div>
  155. </li>
  156. <li>
  157. </li>
  158. <li id="cpython-language-and-version">
  159. <a href="../index.html">3.12.3 Documentation</a> &#187;
  160. </li>
  161. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  162. <li class="nav-item nav-item-2"><a href="markup.html" accesskey="U">Structured Markup Processing Tools</a> &#187;</li>
  163. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code> — The Document Object Model API</a></li>
  164. <li class="right">
  165. <div class="inline-search" role="search">
  166. <form class="inline-search" action="../search.html" method="get">
  167. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  168. <input type="submit" value="Go" />
  169. </form>
  170. </div>
  171. |
  172. </li>
  173. <li class="right">
  174. <label class="theme-selector-label">
  175. Theme
  176. <select class="theme-selector" oninput="activateTheme(this.value)">
  177. <option value="auto" selected>Auto</option>
  178. <option value="light">Light</option>
  179. <option value="dark">Dark</option>
  180. </select>
  181. </label> |</li>
  182. </ul>
  183. </div>
  184. <div class="document">
  185. <div class="documentwrapper">
  186. <div class="bodywrapper">
  187. <div class="body" role="main">
  188. <section id="module-xml.dom">
  189. <span id="xml-dom-the-document-object-model-api"></span><h1><a class="reference internal" href="#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code></a> — The Document Object Model API<a class="headerlink" href="#module-xml.dom" title="Link to this heading">¶</a></h1>
  190. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/xml/dom/__init__.py">Lib/xml/dom/__init__.py</a></p>
  191. <hr class="docutils" />
  192. <p>The Document Object Model, or “DOM,” is a cross-language API from the World Wide
  193. Web Consortium (W3C) for accessing and modifying XML documents. A DOM
  194. implementation presents an XML document as a tree structure, or allows client
  195. code to build such a structure from scratch. It then gives access to the
  196. structure through a set of objects which provided well-known interfaces.</p>
  197. <p>The DOM is extremely useful for random-access applications. SAX only allows you
  198. a view of one bit of the document at a time. If you are looking at one SAX
  199. element, you have no access to another. If you are looking at a text node, you
  200. have no access to a containing element. When you write a SAX application, you
  201. need to keep track of your program’s position in the document somewhere in your
  202. own code. SAX does not do it for you. Also, if you need to look ahead in the
  203. XML document, you are just out of luck.</p>
  204. <p>Some applications are simply impossible in an event driven model with no access
  205. to a tree. Of course you could build some sort of tree yourself in SAX events,
  206. but the DOM allows you to avoid writing that code. The DOM is a standard tree
  207. representation for XML data.</p>
  208. <p>The Document Object Model is being defined by the W3C in stages, or “levels” in
  209. their terminology. The Python mapping of the API is substantially based on the
  210. DOM Level 2 recommendation.</p>
  211. <p>DOM applications typically start by parsing some XML into a DOM. How this is
  212. accomplished is not covered at all by DOM Level 1, and Level 2 provides only
  213. limited improvements: There is a <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> object class which
  214. provides access to <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> creation methods, but no way to access an
  215. XML reader/parser/Document builder in an implementation-independent way. There
  216. is also no well-defined way to access these methods without an existing
  217. <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object. In Python, each DOM implementation will provide a
  218. function <a class="reference internal" href="#xml.dom.getDOMImplementation" title="xml.dom.getDOMImplementation"><code class="xref py py-func docutils literal notranslate"><span class="pre">getDOMImplementation()</span></code></a>. DOM Level 3 adds a Load/Store
  219. specification, which defines an interface to the reader, but this is not yet
  220. available in the Python standard library.</p>
  221. <p>Once you have a DOM document object, you can access the parts of your XML
  222. document through its properties and methods. These properties are defined in
  223. the DOM specification; this portion of the reference manual describes the
  224. interpretation of the specification in Python.</p>
  225. <p>The specification provided by the W3C defines the DOM API for Java, ECMAScript,
  226. and OMG IDL. The Python mapping defined here is based in large part on the IDL
  227. version of the specification, but strict compliance is not required (though
  228. implementations are free to support the strict mapping from IDL). See section
  229. <a class="reference internal" href="#dom-conformance"><span class="std std-ref">Conformance</span></a> for a detailed discussion of mapping requirements.</p>
  230. <div class="admonition seealso">
  231. <p class="admonition-title">See also</p>
  232. <dl class="simple">
  233. <dt><a class="reference external" href="https://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/">Document Object Model (DOM) Level 2 Specification</a></dt><dd><p>The W3C recommendation upon which the Python DOM API is based.</p>
  234. </dd>
  235. <dt><a class="reference external" href="https://www.w3.org/TR/REC-DOM-Level-1/">Document Object Model (DOM) Level 1 Specification</a></dt><dd><p>The W3C recommendation for the DOM supported by <a class="reference internal" href="xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a>.</p>
  236. </dd>
  237. <dt><a class="reference external" href="https://www.omg.org/spec/PYTH/1.2/PDF">Python Language Mapping Specification</a></dt><dd><p>This specifies the mapping from OMG IDL to Python.</p>
  238. </dd>
  239. </dl>
  240. </div>
  241. <section id="module-contents">
  242. <h2>Module Contents<a class="headerlink" href="#module-contents" title="Link to this heading">¶</a></h2>
  243. <p>The <a class="reference internal" href="#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code></a> contains the following functions:</p>
  244. <dl class="py function">
  245. <dt class="sig sig-object py" id="xml.dom.registerDOMImplementation">
  246. <span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">registerDOMImplementation</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">factory</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.registerDOMImplementation" title="Link to this definition">¶</a></dt>
  247. <dd><p>Register the <em>factory</em> function with the name <em>name</em>. The factory function
  248. should return an object which implements the <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code>
  249. interface. The factory function can return the same object every time, or a new
  250. one for each call, as appropriate for the specific implementation (e.g. if that
  251. implementation supports some customization).</p>
  252. </dd></dl>
  253. <dl class="py function">
  254. <dt class="sig sig-object py" id="xml.dom.getDOMImplementation">
  255. <span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">getDOMImplementation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</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">features</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.dom.getDOMImplementation" title="Link to this definition">¶</a></dt>
  256. <dd><p>Return a suitable DOM implementation. The <em>name</em> is either well-known, the
  257. module name of a DOM implementation, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. If it is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, imports
  258. the corresponding module and returns a <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> object if the
  259. import succeeds. If no name is given, and if the environment variable
  260. <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_DOM</span></code> is set, this variable is used to find the implementation.</p>
  261. <p>If name is not given, this examines the available implementations to find one
  262. with the required feature set. If no implementation can be found, raise an
  263. <a class="reference internal" href="exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>. The features list must be a sequence of <code class="docutils literal notranslate"><span class="pre">(feature,</span>
  264. <span class="pre">version)</span></code> pairs which are passed to the <code class="xref py py-meth docutils literal notranslate"><span class="pre">hasFeature()</span></code> method on available
  265. <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> objects.</p>
  266. </dd></dl>
  267. <p>Some convenience constants are also provided:</p>
  268. <dl class="py data">
  269. <dt class="sig sig-object py" id="xml.dom.EMPTY_NAMESPACE">
  270. <span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">EMPTY_NAMESPACE</span></span><a class="headerlink" href="#xml.dom.EMPTY_NAMESPACE" title="Link to this definition">¶</a></dt>
  271. <dd><p>The value used to indicate that no namespace is associated with a node in the
  272. DOM. This is typically found as the <code class="xref py py-attr docutils literal notranslate"><span class="pre">namespaceURI</span></code> of a node, or used as
  273. the <em>namespaceURI</em> parameter to a namespaces-specific method.</p>
  274. </dd></dl>
  275. <dl class="py data">
  276. <dt class="sig sig-object py" id="xml.dom.XML_NAMESPACE">
  277. <span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">XML_NAMESPACE</span></span><a class="headerlink" href="#xml.dom.XML_NAMESPACE" title="Link to this definition">¶</a></dt>
  278. <dd><p>The namespace URI associated with the reserved prefix <code class="docutils literal notranslate"><span class="pre">xml</span></code>, as defined by
  279. <a class="reference external" href="https://www.w3.org/TR/REC-xml-names/">Namespaces in XML</a> (section 4).</p>
  280. </dd></dl>
  281. <dl class="py data">
  282. <dt class="sig sig-object py" id="xml.dom.XMLNS_NAMESPACE">
  283. <span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">XMLNS_NAMESPACE</span></span><a class="headerlink" href="#xml.dom.XMLNS_NAMESPACE" title="Link to this definition">¶</a></dt>
  284. <dd><p>The namespace URI for namespace declarations, as defined by <a class="reference external" href="https://www.w3.org/TR/DOM-Level-2-Core/core.html">Document Object
  285. Model (DOM) Level 2 Core Specification</a> (section 1.1.8).</p>
  286. </dd></dl>
  287. <dl class="py data">
  288. <dt class="sig sig-object py" id="xml.dom.XHTML_NAMESPACE">
  289. <span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">XHTML_NAMESPACE</span></span><a class="headerlink" href="#xml.dom.XHTML_NAMESPACE" title="Link to this definition">¶</a></dt>
  290. <dd><p>The URI of the XHTML namespace as defined by <a class="reference external" href="https://www.w3.org/TR/xhtml1/">XHTML 1.0: The Extensible
  291. HyperText Markup Language</a> (section 3.1.1).</p>
  292. </dd></dl>
  293. <p>In addition, <a class="reference internal" href="#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code></a> contains a base <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> class and the DOM
  294. exception classes. The <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> class provided by this module does not
  295. implement any of the methods or attributes defined by the DOM specification;
  296. concrete DOM implementations must provide those. The <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> class
  297. provided as part of this module does provide the constants used for the
  298. <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeType</span></code> attribute on concrete <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> objects; they are located
  299. within the class rather than at the module level to conform with the DOM
  300. specifications.</p>
  301. </section>
  302. <section id="objects-in-the-dom">
  303. <span id="dom-objects"></span><h2>Objects in the DOM<a class="headerlink" href="#objects-in-the-dom" title="Link to this heading">¶</a></h2>
  304. <p>The definitive documentation for the DOM is the DOM specification from the W3C.</p>
  305. <p>Note that DOM attributes may also be manipulated as nodes instead of as simple
  306. strings. It is fairly rare that you must do this, however, so this usage is not
  307. yet documented.</p>
  308. <table class="docutils align-default">
  309. <thead>
  310. <tr class="row-odd"><th class="head"><p>Interface</p></th>
  311. <th class="head"><p>Section</p></th>
  312. <th class="head"><p>Purpose</p></th>
  313. </tr>
  314. </thead>
  315. <tbody>
  316. <tr class="row-even"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code></p></td>
  317. <td><p><a class="reference internal" href="#dom-implementation-objects"><span class="std std-ref">DOMImplementation Objects</span></a></p></td>
  318. <td><p>Interface to the underlying
  319. implementation.</p></td>
  320. </tr>
  321. <tr class="row-odd"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code></p></td>
  322. <td><p><a class="reference internal" href="#dom-node-objects"><span class="std std-ref">Node Objects</span></a></p></td>
  323. <td><p>Base interface for most objects
  324. in a document.</p></td>
  325. </tr>
  326. <tr class="row-even"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code></p></td>
  327. <td><p><a class="reference internal" href="#dom-nodelist-objects"><span class="std std-ref">NodeList Objects</span></a></p></td>
  328. <td><p>Interface for a sequence of
  329. nodes.</p></td>
  330. </tr>
  331. <tr class="row-odd"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code></p></td>
  332. <td><p><a class="reference internal" href="#dom-documenttype-objects"><span class="std std-ref">DocumentType Objects</span></a></p></td>
  333. <td><p>Information about the
  334. declarations needed to process
  335. a document.</p></td>
  336. </tr>
  337. <tr class="row-even"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code></p></td>
  338. <td><p><a class="reference internal" href="#dom-document-objects"><span class="std std-ref">Document Objects</span></a></p></td>
  339. <td><p>Object which represents an
  340. entire document.</p></td>
  341. </tr>
  342. <tr class="row-odd"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code></p></td>
  343. <td><p><a class="reference internal" href="#dom-element-objects"><span class="std std-ref">Element Objects</span></a></p></td>
  344. <td><p>Element nodes in the document
  345. hierarchy.</p></td>
  346. </tr>
  347. <tr class="row-even"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code></p></td>
  348. <td><p><a class="reference internal" href="#dom-attr-objects"><span class="std std-ref">Attr Objects</span></a></p></td>
  349. <td><p>Attribute value nodes on
  350. element nodes.</p></td>
  351. </tr>
  352. <tr class="row-odd"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Comment</span></code></p></td>
  353. <td><p><a class="reference internal" href="#dom-comment-objects"><span class="std std-ref">Comment Objects</span></a></p></td>
  354. <td><p>Representation of comments in
  355. the source document.</p></td>
  356. </tr>
  357. <tr class="row-even"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Text</span></code></p></td>
  358. <td><p><a class="reference internal" href="#dom-text-objects"><span class="std std-ref">Text and CDATASection Objects</span></a></p></td>
  359. <td><p>Nodes containing textual
  360. content from the document.</p></td>
  361. </tr>
  362. <tr class="row-odd"><td><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessingInstruction</span></code></p></td>
  363. <td><p><a class="reference internal" href="#dom-pi-objects"><span class="std std-ref">ProcessingInstruction Objects</span></a></p></td>
  364. <td><p>Processing instruction
  365. representation.</p></td>
  366. </tr>
  367. </tbody>
  368. </table>
  369. <p>An additional section describes the exceptions defined for working with the DOM
  370. in Python.</p>
  371. <section id="domimplementation-objects">
  372. <span id="dom-implementation-objects"></span><h3>DOMImplementation Objects<a class="headerlink" href="#domimplementation-objects" title="Link to this heading">¶</a></h3>
  373. <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> interface provides a way for applications to
  374. determine the availability of particular features in the DOM they are using.
  375. DOM Level 2 added the ability to create new <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> and
  376. <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> objects using the <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> as well.</p>
  377. <dl class="py method">
  378. <dt class="sig sig-object py" id="xml.dom.DOMImplementation.hasFeature">
  379. <span class="sig-prename descclassname"><span class="pre">DOMImplementation.</span></span><span class="sig-name descname"><span class="pre">hasFeature</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">feature</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">version</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.DOMImplementation.hasFeature" title="Link to this definition">¶</a></dt>
  380. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the feature identified by the pair of strings <em>feature</em> and
  381. <em>version</em> is implemented.</p>
  382. </dd></dl>
  383. <dl class="py method">
  384. <dt class="sig sig-object py" id="xml.dom.DOMImplementation.createDocument">
  385. <span class="sig-prename descclassname"><span class="pre">DOMImplementation.</span></span><span class="sig-name descname"><span class="pre">createDocument</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceUri</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">qualifiedName</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">doctype</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.DOMImplementation.createDocument" title="Link to this definition">¶</a></dt>
  386. <dd><p>Return a new <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object (the root of the DOM), with a child
  387. <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object having the given <em>namespaceUri</em> and <em>qualifiedName</em>. The
  388. <em>doctype</em> must be a <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> object created by
  389. <a class="reference internal" href="#xml.dom.DOMImplementation.createDocumentType" title="xml.dom.DOMImplementation.createDocumentType"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createDocumentType()</span></code></a>, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. In the Python DOM API, the first two
  390. arguments can also be <code class="docutils literal notranslate"><span class="pre">None</span></code> in order to indicate that no <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code>
  391. child is to be created.</p>
  392. </dd></dl>
  393. <dl class="py method">
  394. <dt class="sig sig-object py" id="xml.dom.DOMImplementation.createDocumentType">
  395. <span class="sig-prename descclassname"><span class="pre">DOMImplementation.</span></span><span class="sig-name descname"><span class="pre">createDocumentType</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qualifiedName</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">publicId</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">systemId</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.DOMImplementation.createDocumentType" title="Link to this definition">¶</a></dt>
  396. <dd><p>Return a new <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> object that encapsulates the given
  397. <em>qualifiedName</em>, <em>publicId</em>, and <em>systemId</em> strings, representing the
  398. information contained in an XML document type declaration.</p>
  399. </dd></dl>
  400. </section>
  401. <section id="node-objects">
  402. <span id="dom-node-objects"></span><h3>Node Objects<a class="headerlink" href="#node-objects" title="Link to this heading">¶</a></h3>
  403. <p>All of the components of an XML document are subclasses of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>.</p>
  404. <dl class="py attribute">
  405. <dt class="sig sig-object py" id="xml.dom.Node.nodeType">
  406. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">nodeType</span></span><a class="headerlink" href="#xml.dom.Node.nodeType" title="Link to this definition">¶</a></dt>
  407. <dd><p>An integer representing the node type. Symbolic constants for the types are on
  408. the <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> object: <code class="xref py py-const docutils literal notranslate"><span class="pre">ELEMENT_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ATTRIBUTE_NODE</span></code>,
  409. <code class="xref py py-const docutils literal notranslate"><span class="pre">TEXT_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">CDATA_SECTION_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ENTITY_NODE</span></code>,
  410. <code class="xref py py-const docutils literal notranslate"><span class="pre">PROCESSING_INSTRUCTION_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">COMMENT_NODE</span></code>,
  411. <code class="xref py py-const docutils literal notranslate"><span class="pre">DOCUMENT_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">DOCUMENT_TYPE_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTATION_NODE</span></code>.
  412. This is a read-only attribute.</p>
  413. </dd></dl>
  414. <dl class="py attribute">
  415. <dt class="sig sig-object py" id="xml.dom.Node.parentNode">
  416. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">parentNode</span></span><a class="headerlink" href="#xml.dom.Node.parentNode" title="Link to this definition">¶</a></dt>
  417. <dd><p>The parent of the current node, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for the document node. The value is
  418. always a <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> object or <code class="docutils literal notranslate"><span class="pre">None</span></code>. For <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> nodes, this
  419. will be the parent element, except for the root element, in which case it will
  420. be the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object. For <code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> nodes, this is always
  421. <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p>
  422. </dd></dl>
  423. <dl class="py attribute">
  424. <dt class="sig sig-object py" id="xml.dom.Node.attributes">
  425. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">attributes</span></span><a class="headerlink" href="#xml.dom.Node.attributes" title="Link to this definition">¶</a></dt>
  426. <dd><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> of attribute objects. Only elements have actual values
  427. for this; others provide <code class="docutils literal notranslate"><span class="pre">None</span></code> for this attribute. This is a read-only
  428. attribute.</p>
  429. </dd></dl>
  430. <dl class="py attribute">
  431. <dt class="sig sig-object py" id="xml.dom.Node.previousSibling">
  432. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">previousSibling</span></span><a class="headerlink" href="#xml.dom.Node.previousSibling" title="Link to this definition">¶</a></dt>
  433. <dd><p>The node that immediately precedes this one with the same parent. For
  434. instance the element with an end-tag that comes just before the <em>self</em>
  435. element’s start-tag. Of course, XML documents are made up of more than just
  436. elements so the previous sibling could be text, a comment, or something else.
  437. If this node is the first child of the parent, this attribute will be
  438. <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p>
  439. </dd></dl>
  440. <dl class="py attribute">
  441. <dt class="sig sig-object py" id="xml.dom.Node.nextSibling">
  442. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">nextSibling</span></span><a class="headerlink" href="#xml.dom.Node.nextSibling" title="Link to this definition">¶</a></dt>
  443. <dd><p>The node that immediately follows this one with the same parent. See also
  444. <a class="reference internal" href="#xml.dom.Node.previousSibling" title="xml.dom.Node.previousSibling"><code class="xref py py-attr docutils literal notranslate"><span class="pre">previousSibling</span></code></a>. If this is the last child of the parent, this
  445. attribute will be <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p>
  446. </dd></dl>
  447. <dl class="py attribute">
  448. <dt class="sig sig-object py" id="xml.dom.Node.childNodes">
  449. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">childNodes</span></span><a class="headerlink" href="#xml.dom.Node.childNodes" title="Link to this definition">¶</a></dt>
  450. <dd><p>A list of nodes contained within this node. This is a read-only attribute.</p>
  451. </dd></dl>
  452. <dl class="py attribute">
  453. <dt class="sig sig-object py" id="xml.dom.Node.firstChild">
  454. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">firstChild</span></span><a class="headerlink" href="#xml.dom.Node.firstChild" title="Link to this definition">¶</a></dt>
  455. <dd><p>The first child of the node, if there are any, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only
  456. attribute.</p>
  457. </dd></dl>
  458. <dl class="py attribute">
  459. <dt class="sig sig-object py" id="xml.dom.Node.lastChild">
  460. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">lastChild</span></span><a class="headerlink" href="#xml.dom.Node.lastChild" title="Link to this definition">¶</a></dt>
  461. <dd><p>The last child of the node, if there are any, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only
  462. attribute.</p>
  463. </dd></dl>
  464. <dl class="py attribute">
  465. <dt class="sig sig-object py" id="xml.dom.Node.localName">
  466. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">localName</span></span><a class="headerlink" href="#xml.dom.Node.localName" title="Link to this definition">¶</a></dt>
  467. <dd><p>The part of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code> following the colon if there is one, else the
  468. entire <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code>. The value is a string.</p>
  469. </dd></dl>
  470. <dl class="py attribute">
  471. <dt class="sig sig-object py" id="xml.dom.Node.prefix">
  472. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">prefix</span></span><a class="headerlink" href="#xml.dom.Node.prefix" title="Link to this definition">¶</a></dt>
  473. <dd><p>The part of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code> preceding the colon if there is one, else the
  474. empty string. The value is a string, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  475. </dd></dl>
  476. <dl class="py attribute">
  477. <dt class="sig sig-object py" id="xml.dom.Node.namespaceURI">
  478. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">namespaceURI</span></span><a class="headerlink" href="#xml.dom.Node.namespaceURI" title="Link to this definition">¶</a></dt>
  479. <dd><p>The namespace associated with the element name. This will be a string or
  480. <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p>
  481. </dd></dl>
  482. <dl class="py attribute">
  483. <dt class="sig sig-object py" id="xml.dom.Node.nodeName">
  484. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">nodeName</span></span><a class="headerlink" href="#xml.dom.Node.nodeName" title="Link to this definition">¶</a></dt>
  485. <dd><p>This has a different meaning for each node type; see the DOM specification for
  486. details. You can always get the information you would get here from another
  487. property such as the <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code> property for elements or the <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code>
  488. property for attributes. For all node types, the value of this attribute will be
  489. either a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p>
  490. </dd></dl>
  491. <dl class="py attribute">
  492. <dt class="sig sig-object py" id="xml.dom.Node.nodeValue">
  493. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">nodeValue</span></span><a class="headerlink" href="#xml.dom.Node.nodeValue" title="Link to this definition">¶</a></dt>
  494. <dd><p>This has a different meaning for each node type; see the DOM specification for
  495. details. The situation is similar to that with <a class="reference internal" href="#xml.dom.Node.nodeName" title="xml.dom.Node.nodeName"><code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeName</span></code></a>. The value is
  496. a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  497. </dd></dl>
  498. <dl class="py method">
  499. <dt class="sig sig-object py" id="xml.dom.Node.hasAttributes">
  500. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">hasAttributes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.hasAttributes" title="Link to this definition">¶</a></dt>
  501. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the node has any attributes.</p>
  502. </dd></dl>
  503. <dl class="py method">
  504. <dt class="sig sig-object py" id="xml.dom.Node.hasChildNodes">
  505. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">hasChildNodes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.hasChildNodes" title="Link to this definition">¶</a></dt>
  506. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the node has any child nodes.</p>
  507. </dd></dl>
  508. <dl class="py method">
  509. <dt class="sig sig-object py" id="xml.dom.Node.isSameNode">
  510. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">isSameNode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.isSameNode" title="Link to this definition">¶</a></dt>
  511. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if <em>other</em> refers to the same node as this node. This is especially
  512. useful for DOM implementations which use any sort of proxy architecture (because
  513. more than one object can refer to the same node).</p>
  514. <div class="admonition note">
  515. <p class="admonition-title">Note</p>
  516. <p>This is based on a proposed DOM Level 3 API which is still in the “working
  517. draft” stage, but this particular interface appears uncontroversial. Changes
  518. from the W3C will not necessarily affect this method in the Python DOM interface
  519. (though any new W3C API for this would also be supported).</p>
  520. </div>
  521. </dd></dl>
  522. <dl class="py method">
  523. <dt class="sig sig-object py" id="xml.dom.Node.appendChild">
  524. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">appendChild</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">newChild</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.appendChild" title="Link to this definition">¶</a></dt>
  525. <dd><p>Add a new child node to this node at the end of the list of
  526. children, returning <em>newChild</em>. If the node was already in
  527. the tree, it is removed first.</p>
  528. </dd></dl>
  529. <dl class="py method">
  530. <dt class="sig sig-object py" id="xml.dom.Node.insertBefore">
  531. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">insertBefore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">newChild</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">refChild</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.insertBefore" title="Link to this definition">¶</a></dt>
  532. <dd><p>Insert a new child node before an existing child. It must be the case that
  533. <em>refChild</em> is a child of this node; if not, <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> is raised.
  534. <em>newChild</em> is returned. If <em>refChild</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, it inserts <em>newChild</em> at the
  535. end of the children’s list.</p>
  536. </dd></dl>
  537. <dl class="py method">
  538. <dt class="sig sig-object py" id="xml.dom.Node.removeChild">
  539. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">removeChild</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">oldChild</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.removeChild" title="Link to this definition">¶</a></dt>
  540. <dd><p>Remove a child node. <em>oldChild</em> must be a child of this node; if not,
  541. <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> is raised. <em>oldChild</em> is returned on success. If <em>oldChild</em>
  542. will not be used further, its <code class="xref py py-meth docutils literal notranslate"><span class="pre">unlink()</span></code> method should be called.</p>
  543. </dd></dl>
  544. <dl class="py method">
  545. <dt class="sig sig-object py" id="xml.dom.Node.replaceChild">
  546. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">replaceChild</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">newChild</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">oldChild</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.replaceChild" title="Link to this definition">¶</a></dt>
  547. <dd><p>Replace an existing node with a new node. It must be the case that <em>oldChild</em>
  548. is a child of this node; if not, <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> is raised.</p>
  549. </dd></dl>
  550. <dl class="py method">
  551. <dt class="sig sig-object py" id="xml.dom.Node.normalize">
  552. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">normalize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.normalize" title="Link to this definition">¶</a></dt>
  553. <dd><p>Join adjacent text nodes so that all stretches of text are stored as single
  554. <code class="xref py py-class docutils literal notranslate"><span class="pre">Text</span></code> instances. This simplifies processing text from a DOM tree for
  555. many applications.</p>
  556. </dd></dl>
  557. <dl class="py method">
  558. <dt class="sig sig-object py" id="xml.dom.Node.cloneNode">
  559. <span class="sig-prename descclassname"><span class="pre">Node.</span></span><span class="sig-name descname"><span class="pre">cloneNode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">deep</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.cloneNode" title="Link to this definition">¶</a></dt>
  560. <dd><p>Clone this node. Setting <em>deep</em> means to clone all child nodes as well. This
  561. returns the clone.</p>
  562. </dd></dl>
  563. </section>
  564. <section id="nodelist-objects">
  565. <span id="dom-nodelist-objects"></span><h3>NodeList Objects<a class="headerlink" href="#nodelist-objects" title="Link to this heading">¶</a></h3>
  566. <p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> represents a sequence of nodes. These objects are used in
  567. two ways in the DOM Core recommendation: an <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object provides
  568. one as its list of child nodes, and the <code class="xref py py-meth docutils literal notranslate"><span class="pre">getElementsByTagName()</span></code> and
  569. <code class="xref py py-meth docutils literal notranslate"><span class="pre">getElementsByTagNameNS()</span></code> methods of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> return objects with this
  570. interface to represent query results.</p>
  571. <p>The DOM Level 2 recommendation defines one method and one attribute for these
  572. objects:</p>
  573. <dl class="py method">
  574. <dt class="sig sig-object py" id="xml.dom.NodeList.item">
  575. <span class="sig-prename descclassname"><span class="pre">NodeList.</span></span><span class="sig-name descname"><span class="pre">item</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.NodeList.item" title="Link to this definition">¶</a></dt>
  576. <dd><p>Return the <em>i</em>’th item from the sequence, if there is one, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. The
  577. index <em>i</em> is not allowed to be less than zero or greater than or equal to the
  578. length of the sequence.</p>
  579. </dd></dl>
  580. <dl class="py attribute">
  581. <dt class="sig sig-object py" id="xml.dom.NodeList.length">
  582. <span class="sig-prename descclassname"><span class="pre">NodeList.</span></span><span class="sig-name descname"><span class="pre">length</span></span><a class="headerlink" href="#xml.dom.NodeList.length" title="Link to this definition">¶</a></dt>
  583. <dd><p>The number of nodes in the sequence.</p>
  584. </dd></dl>
  585. <p>In addition, the Python DOM interface requires that some additional support is
  586. provided to allow <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> objects to be used as Python sequences. All
  587. <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> implementations must include support for
  588. <a class="reference internal" href="../reference/datamodel.html#object.__len__" title="object.__len__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__len__()</span></code></a> and
  589. <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>; this allows iteration over the <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> in
  590. <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a> statements and proper support for the <a class="reference internal" href="functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> built-in
  591. function.</p>
  592. <p>If a DOM implementation supports modification of the document, the
  593. <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> implementation must also support the
  594. <a class="reference internal" href="../reference/datamodel.html#object.__setitem__" title="object.__setitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setitem__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__delitem__" title="object.__delitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__delitem__()</span></code></a> methods.</p>
  595. </section>
  596. <section id="documenttype-objects">
  597. <span id="dom-documenttype-objects"></span><h3>DocumentType Objects<a class="headerlink" href="#documenttype-objects" title="Link to this heading">¶</a></h3>
  598. <p>Information about the notations and entities declared by a document (including
  599. the external subset if the parser uses it and can provide the information) is
  600. available from a <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> object. The <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> for a
  601. document is available from the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">doctype</span></code>
  602. attribute; if there is no <code class="docutils literal notranslate"><span class="pre">DOCTYPE</span></code> declaration for the document, the
  603. document’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">doctype</span></code> attribute will be set to <code class="docutils literal notranslate"><span class="pre">None</span></code> instead of an
  604. instance of this interface.</p>
  605. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> is a specialization of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, and adds the
  606. following attributes:</p>
  607. <dl class="py attribute">
  608. <dt class="sig sig-object py" id="xml.dom.DocumentType.publicId">
  609. <span class="sig-prename descclassname"><span class="pre">DocumentType.</span></span><span class="sig-name descname"><span class="pre">publicId</span></span><a class="headerlink" href="#xml.dom.DocumentType.publicId" title="Link to this definition">¶</a></dt>
  610. <dd><p>The public identifier for the external subset of the document type definition.
  611. This will be a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  612. </dd></dl>
  613. <dl class="py attribute">
  614. <dt class="sig sig-object py" id="xml.dom.DocumentType.systemId">
  615. <span class="sig-prename descclassname"><span class="pre">DocumentType.</span></span><span class="sig-name descname"><span class="pre">systemId</span></span><a class="headerlink" href="#xml.dom.DocumentType.systemId" title="Link to this definition">¶</a></dt>
  616. <dd><p>The system identifier for the external subset of the document type definition.
  617. This will be a URI as a string, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  618. </dd></dl>
  619. <dl class="py attribute">
  620. <dt class="sig sig-object py" id="xml.dom.DocumentType.internalSubset">
  621. <span class="sig-prename descclassname"><span class="pre">DocumentType.</span></span><span class="sig-name descname"><span class="pre">internalSubset</span></span><a class="headerlink" href="#xml.dom.DocumentType.internalSubset" title="Link to this definition">¶</a></dt>
  622. <dd><p>A string giving the complete internal subset from the document. This does not
  623. include the brackets which enclose the subset. If the document has no internal
  624. subset, this should be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  625. </dd></dl>
  626. <dl class="py attribute">
  627. <dt class="sig sig-object py" id="xml.dom.DocumentType.name">
  628. <span class="sig-prename descclassname"><span class="pre">DocumentType.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#xml.dom.DocumentType.name" title="Link to this definition">¶</a></dt>
  629. <dd><p>The name of the root element as given in the <code class="docutils literal notranslate"><span class="pre">DOCTYPE</span></code> declaration, if
  630. present.</p>
  631. </dd></dl>
  632. <dl class="py attribute">
  633. <dt class="sig sig-object py" id="xml.dom.DocumentType.entities">
  634. <span class="sig-prename descclassname"><span class="pre">DocumentType.</span></span><span class="sig-name descname"><span class="pre">entities</span></span><a class="headerlink" href="#xml.dom.DocumentType.entities" title="Link to this definition">¶</a></dt>
  635. <dd><p>This is a <code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> giving the definitions of external entities.
  636. For entity names defined more than once, only the first definition is provided
  637. (others are ignored as required by the XML recommendation). This may be
  638. <code class="docutils literal notranslate"><span class="pre">None</span></code> if the information is not provided by the parser, or if no entities are
  639. defined.</p>
  640. </dd></dl>
  641. <dl class="py attribute">
  642. <dt class="sig sig-object py" id="xml.dom.DocumentType.notations">
  643. <span class="sig-prename descclassname"><span class="pre">DocumentType.</span></span><span class="sig-name descname"><span class="pre">notations</span></span><a class="headerlink" href="#xml.dom.DocumentType.notations" title="Link to this definition">¶</a></dt>
  644. <dd><p>This is a <code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> giving the definitions of notations. For
  645. notation names defined more than once, only the first definition is provided
  646. (others are ignored as required by the XML recommendation). This may be
  647. <code class="docutils literal notranslate"><span class="pre">None</span></code> if the information is not provided by the parser, or if no notations
  648. are defined.</p>
  649. </dd></dl>
  650. </section>
  651. <section id="document-objects">
  652. <span id="dom-document-objects"></span><h3>Document Objects<a class="headerlink" href="#document-objects" title="Link to this heading">¶</a></h3>
  653. <p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> represents an entire XML document, including its constituent
  654. elements, attributes, processing instructions, comments etc. Remember that it
  655. inherits properties from <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>.</p>
  656. <dl class="py attribute">
  657. <dt class="sig sig-object py" id="xml.dom.Document.documentElement">
  658. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">documentElement</span></span><a class="headerlink" href="#xml.dom.Document.documentElement" title="Link to this definition">¶</a></dt>
  659. <dd><p>The one and only root element of the document.</p>
  660. </dd></dl>
  661. <dl class="py method">
  662. <dt class="sig sig-object py" id="xml.dom.Document.createElement">
  663. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">createElement</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tagName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createElement" title="Link to this definition">¶</a></dt>
  664. <dd><p>Create and return a new element node. The element is not inserted into the
  665. document when it is created. You need to explicitly insert it with one of the
  666. other methods such as <code class="xref py py-meth docutils literal notranslate"><span class="pre">insertBefore()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">appendChild()</span></code>.</p>
  667. </dd></dl>
  668. <dl class="py method">
  669. <dt class="sig sig-object py" id="xml.dom.Document.createElementNS">
  670. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">createElementNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tagName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createElementNS" title="Link to this definition">¶</a></dt>
  671. <dd><p>Create and return a new element with a namespace. The <em>tagName</em> may have a
  672. prefix. The element is not inserted into the document when it is created. You
  673. need to explicitly insert it with one of the other methods such as
  674. <code class="xref py py-meth docutils literal notranslate"><span class="pre">insertBefore()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">appendChild()</span></code>.</p>
  675. </dd></dl>
  676. <dl class="py method">
  677. <dt class="sig sig-object py" id="xml.dom.Document.createTextNode">
  678. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">createTextNode</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.dom.Document.createTextNode" title="Link to this definition">¶</a></dt>
  679. <dd><p>Create and return a text node containing the data passed as a parameter. As
  680. with the other creation methods, this one does not insert the node into the
  681. tree.</p>
  682. </dd></dl>
  683. <dl class="py method">
  684. <dt class="sig sig-object py" id="xml.dom.Document.createComment">
  685. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">createComment</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.dom.Document.createComment" title="Link to this definition">¶</a></dt>
  686. <dd><p>Create and return a comment node containing the data passed as a parameter. As
  687. with the other creation methods, this one does not insert the node into the
  688. tree.</p>
  689. </dd></dl>
  690. <dl class="py method">
  691. <dt class="sig sig-object py" id="xml.dom.Document.createProcessingInstruction">
  692. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">createProcessingInstruction</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.dom.Document.createProcessingInstruction" title="Link to this definition">¶</a></dt>
  693. <dd><p>Create and return a processing instruction node containing the <em>target</em> and
  694. <em>data</em> passed as parameters. As with the other creation methods, this one does
  695. not insert the node into the tree.</p>
  696. </dd></dl>
  697. <dl class="py method">
  698. <dt class="sig sig-object py" id="xml.dom.Document.createAttribute">
  699. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">createAttribute</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.dom.Document.createAttribute" title="Link to this definition">¶</a></dt>
  700. <dd><p>Create and return an attribute node. This method does not associate the
  701. attribute node with any particular element. You must use
  702. <code class="xref py py-meth docutils literal notranslate"><span class="pre">setAttributeNode()</span></code> on the appropriate <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object to use the
  703. newly created attribute instance.</p>
  704. </dd></dl>
  705. <dl class="py method">
  706. <dt class="sig sig-object py" id="xml.dom.Document.createAttributeNS">
  707. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">createAttributeNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">qualifiedName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createAttributeNS" title="Link to this definition">¶</a></dt>
  708. <dd><p>Create and return an attribute node with a namespace. The <em>tagName</em> may have a
  709. prefix. This method does not associate the attribute node with any particular
  710. element. You must use <code class="xref py py-meth docutils literal notranslate"><span class="pre">setAttributeNode()</span></code> on the appropriate
  711. <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object to use the newly created attribute instance.</p>
  712. </dd></dl>
  713. <dl class="py method">
  714. <dt class="sig sig-object py" id="xml.dom.Document.getElementsByTagName">
  715. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">getElementsByTagName</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tagName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.getElementsByTagName" title="Link to this definition">¶</a></dt>
  716. <dd><p>Search for all descendants (direct children, children’s children, etc.) with a
  717. particular element type name.</p>
  718. </dd></dl>
  719. <dl class="py method">
  720. <dt class="sig sig-object py" id="xml.dom.Document.getElementsByTagNameNS">
  721. <span class="sig-prename descclassname"><span class="pre">Document.</span></span><span class="sig-name descname"><span class="pre">getElementsByTagNameNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">localName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.getElementsByTagNameNS" title="Link to this definition">¶</a></dt>
  722. <dd><p>Search for all descendants (direct children, children’s children, etc.) with a
  723. particular namespace URI and localname. The localname is the part of the
  724. namespace after the prefix.</p>
  725. </dd></dl>
  726. </section>
  727. <section id="element-objects">
  728. <span id="dom-element-objects"></span><h3>Element Objects<a class="headerlink" href="#element-objects" title="Link to this heading">¶</a></h3>
  729. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> is a subclass of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, so inherits all the attributes
  730. of that class.</p>
  731. <dl class="py attribute">
  732. <dt class="sig sig-object py" id="xml.dom.Element.tagName">
  733. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">tagName</span></span><a class="headerlink" href="#xml.dom.Element.tagName" title="Link to this definition">¶</a></dt>
  734. <dd><p>The element type name. In a namespace-using document it may have colons in it.
  735. The value is a string.</p>
  736. </dd></dl>
  737. <dl class="py method">
  738. <dt class="sig sig-object py" id="xml.dom.Element.getElementsByTagName">
  739. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">getElementsByTagName</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tagName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getElementsByTagName" title="Link to this definition">¶</a></dt>
  740. <dd><p>Same as equivalent method in the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> class.</p>
  741. </dd></dl>
  742. <dl class="py method">
  743. <dt class="sig sig-object py" id="xml.dom.Element.getElementsByTagNameNS">
  744. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">getElementsByTagNameNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">localName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getElementsByTagNameNS" title="Link to this definition">¶</a></dt>
  745. <dd><p>Same as equivalent method in the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> class.</p>
  746. </dd></dl>
  747. <dl class="py method">
  748. <dt class="sig sig-object py" id="xml.dom.Element.hasAttribute">
  749. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">hasAttribute</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.dom.Element.hasAttribute" title="Link to this definition">¶</a></dt>
  750. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the element has an attribute named by <em>name</em>.</p>
  751. </dd></dl>
  752. <dl class="py method">
  753. <dt class="sig sig-object py" id="xml.dom.Element.hasAttributeNS">
  754. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">hasAttributeNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">localName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.hasAttributeNS" title="Link to this definition">¶</a></dt>
  755. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the element has an attribute named by <em>namespaceURI</em> and
  756. <em>localName</em>.</p>
  757. </dd></dl>
  758. <dl class="py method">
  759. <dt class="sig sig-object py" id="xml.dom.Element.getAttribute">
  760. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">getAttribute</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.dom.Element.getAttribute" title="Link to this definition">¶</a></dt>
  761. <dd><p>Return the value of the attribute named by <em>name</em> as a string. If no such
  762. attribute exists, an empty string is returned, as if the attribute had no value.</p>
  763. </dd></dl>
  764. <dl class="py method">
  765. <dt class="sig sig-object py" id="xml.dom.Element.getAttributeNode">
  766. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">getAttributeNode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">attrname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getAttributeNode" title="Link to this definition">¶</a></dt>
  767. <dd><p>Return the <code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> node for the attribute named by <em>attrname</em>.</p>
  768. </dd></dl>
  769. <dl class="py method">
  770. <dt class="sig sig-object py" id="xml.dom.Element.getAttributeNS">
  771. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">getAttributeNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">localName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getAttributeNS" title="Link to this definition">¶</a></dt>
  772. <dd><p>Return the value of the attribute named by <em>namespaceURI</em> and <em>localName</em> as a
  773. string. If no such attribute exists, an empty string is returned, as if the
  774. attribute had no value.</p>
  775. </dd></dl>
  776. <dl class="py method">
  777. <dt class="sig sig-object py" id="xml.dom.Element.getAttributeNodeNS">
  778. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">getAttributeNodeNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">localName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getAttributeNodeNS" title="Link to this definition">¶</a></dt>
  779. <dd><p>Return an attribute value as a node, given a <em>namespaceURI</em> and <em>localName</em>.</p>
  780. </dd></dl>
  781. <dl class="py method">
  782. <dt class="sig sig-object py" id="xml.dom.Element.removeAttribute">
  783. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">removeAttribute</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.dom.Element.removeAttribute" title="Link to this definition">¶</a></dt>
  784. <dd><p>Remove an attribute by name. If there is no matching attribute, a
  785. <a class="reference internal" href="#xml.dom.NotFoundErr" title="xml.dom.NotFoundErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFoundErr</span></code></a> is raised.</p>
  786. </dd></dl>
  787. <dl class="py method">
  788. <dt class="sig sig-object py" id="xml.dom.Element.removeAttributeNode">
  789. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">removeAttributeNode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">oldAttr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.removeAttributeNode" title="Link to this definition">¶</a></dt>
  790. <dd><p>Remove and return <em>oldAttr</em> from the attribute list, if present. If <em>oldAttr</em> is
  791. not present, <a class="reference internal" href="#xml.dom.NotFoundErr" title="xml.dom.NotFoundErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFoundErr</span></code></a> is raised.</p>
  792. </dd></dl>
  793. <dl class="py method">
  794. <dt class="sig sig-object py" id="xml.dom.Element.removeAttributeNS">
  795. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">removeAttributeNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">localName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.removeAttributeNS" title="Link to this definition">¶</a></dt>
  796. <dd><p>Remove an attribute by name. Note that it uses a localName, not a qname. No
  797. exception is raised if there is no matching attribute.</p>
  798. </dd></dl>
  799. <dl class="py method">
  800. <dt class="sig sig-object py" id="xml.dom.Element.setAttribute">
  801. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">setAttribute</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">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttribute" title="Link to this definition">¶</a></dt>
  802. <dd><p>Set an attribute value from a string.</p>
  803. </dd></dl>
  804. <dl class="py method">
  805. <dt class="sig sig-object py" id="xml.dom.Element.setAttributeNode">
  806. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">setAttributeNode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">newAttr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttributeNode" title="Link to this definition">¶</a></dt>
  807. <dd><p>Add a new attribute node to the element, replacing an existing attribute if
  808. necessary if the <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code> attribute matches. If a replacement occurs, the
  809. old attribute node will be returned. If <em>newAttr</em> is already in use,
  810. <a class="reference internal" href="#xml.dom.InuseAttributeErr" title="xml.dom.InuseAttributeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InuseAttributeErr</span></code></a> will be raised.</p>
  811. </dd></dl>
  812. <dl class="py method">
  813. <dt class="sig sig-object py" id="xml.dom.Element.setAttributeNodeNS">
  814. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">setAttributeNodeNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">newAttr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttributeNodeNS" title="Link to this definition">¶</a></dt>
  815. <dd><p>Add a new attribute node to the element, replacing an existing attribute if
  816. necessary if the <code class="xref py py-attr docutils literal notranslate"><span class="pre">namespaceURI</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">localName</span></code> attributes match.
  817. If a replacement occurs, the old attribute node will be returned. If <em>newAttr</em>
  818. is already in use, <a class="reference internal" href="#xml.dom.InuseAttributeErr" title="xml.dom.InuseAttributeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InuseAttributeErr</span></code></a> will be raised.</p>
  819. </dd></dl>
  820. <dl class="py method">
  821. <dt class="sig sig-object py" id="xml.dom.Element.setAttributeNS">
  822. <span class="sig-prename descclassname"><span class="pre">Element.</span></span><span class="sig-name descname"><span class="pre">setAttributeNS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespaceURI</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">qname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttributeNS" title="Link to this definition">¶</a></dt>
  823. <dd><p>Set an attribute value from a string, given a <em>namespaceURI</em> and a <em>qname</em>.
  824. Note that a qname is the whole attribute name. This is different than above.</p>
  825. </dd></dl>
  826. </section>
  827. <section id="attr-objects">
  828. <span id="dom-attr-objects"></span><h3>Attr Objects<a class="headerlink" href="#attr-objects" title="Link to this heading">¶</a></h3>
  829. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> inherits from <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, so inherits all its attributes.</p>
  830. <dl class="py attribute">
  831. <dt class="sig sig-object py" id="xml.dom.Attr.name">
  832. <span class="sig-prename descclassname"><span class="pre">Attr.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#xml.dom.Attr.name" title="Link to this definition">¶</a></dt>
  833. <dd><p>The attribute name.
  834. In a namespace-using document it may include a colon.</p>
  835. </dd></dl>
  836. <dl class="py attribute">
  837. <dt class="sig sig-object py" id="xml.dom.Attr.localName">
  838. <span class="sig-prename descclassname"><span class="pre">Attr.</span></span><span class="sig-name descname"><span class="pre">localName</span></span><a class="headerlink" href="#xml.dom.Attr.localName" title="Link to this definition">¶</a></dt>
  839. <dd><p>The part of the name following the colon if there is one, else the
  840. entire name.
  841. This is a read-only attribute.</p>
  842. </dd></dl>
  843. <dl class="py attribute">
  844. <dt class="sig sig-object py" id="xml.dom.Attr.prefix">
  845. <span class="sig-prename descclassname"><span class="pre">Attr.</span></span><span class="sig-name descname"><span class="pre">prefix</span></span><a class="headerlink" href="#xml.dom.Attr.prefix" title="Link to this definition">¶</a></dt>
  846. <dd><p>The part of the name preceding the colon if there is one, else the
  847. empty string.</p>
  848. </dd></dl>
  849. <dl class="py attribute">
  850. <dt class="sig sig-object py" id="xml.dom.Attr.value">
  851. <span class="sig-prename descclassname"><span class="pre">Attr.</span></span><span class="sig-name descname"><span class="pre">value</span></span><a class="headerlink" href="#xml.dom.Attr.value" title="Link to this definition">¶</a></dt>
  852. <dd><p>The text value of the attribute. This is a synonym for the
  853. <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeValue</span></code> attribute.</p>
  854. </dd></dl>
  855. </section>
  856. <section id="namednodemap-objects">
  857. <span id="dom-attributelist-objects"></span><h3>NamedNodeMap Objects<a class="headerlink" href="#namednodemap-objects" title="Link to this heading">¶</a></h3>
  858. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> does <em>not</em> inherit from <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>.</p>
  859. <dl class="py attribute">
  860. <dt class="sig sig-object py" id="xml.dom.NamedNodeMap.length">
  861. <span class="sig-prename descclassname"><span class="pre">NamedNodeMap.</span></span><span class="sig-name descname"><span class="pre">length</span></span><a class="headerlink" href="#xml.dom.NamedNodeMap.length" title="Link to this definition">¶</a></dt>
  862. <dd><p>The length of the attribute list.</p>
  863. </dd></dl>
  864. <dl class="py method">
  865. <dt class="sig sig-object py" id="xml.dom.NamedNodeMap.item">
  866. <span class="sig-prename descclassname"><span class="pre">NamedNodeMap.</span></span><span class="sig-name descname"><span class="pre">item</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">index</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.NamedNodeMap.item" title="Link to this definition">¶</a></dt>
  867. <dd><p>Return an attribute with a particular index. The order you get the attributes
  868. in is arbitrary but will be consistent for the life of a DOM. Each item is an
  869. attribute node. Get its value with the <code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code> attribute.</p>
  870. </dd></dl>
  871. <p>There are also experimental methods that give this class more mapping behavior.
  872. You can use them or you can use the standardized <code class="xref py py-meth docutils literal notranslate"><span class="pre">getAttribute*()</span></code> family
  873. of methods on the <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> objects.</p>
  874. </section>
  875. <section id="comment-objects">
  876. <span id="dom-comment-objects"></span><h3>Comment Objects<a class="headerlink" href="#comment-objects" title="Link to this heading">¶</a></h3>
  877. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">Comment</span></code> represents a comment in the XML document. It is a subclass of
  878. <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, but cannot have child nodes.</p>
  879. <dl class="py attribute">
  880. <dt class="sig sig-object py" id="xml.dom.Comment.data">
  881. <span class="sig-prename descclassname"><span class="pre">Comment.</span></span><span class="sig-name descname"><span class="pre">data</span></span><a class="headerlink" href="#xml.dom.Comment.data" title="Link to this definition">¶</a></dt>
  882. <dd><p>The content of the comment as a string. The attribute contains all characters
  883. between the leading <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>, but does not
  884. include them.</p>
  885. </dd></dl>
  886. </section>
  887. <section id="text-and-cdatasection-objects">
  888. <span id="dom-text-objects"></span><h3>Text and CDATASection Objects<a class="headerlink" href="#text-and-cdatasection-objects" title="Link to this heading">¶</a></h3>
  889. <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">Text</span></code> interface represents text in the XML document. If the parser
  890. and DOM implementation support the DOM’s XML extension, portions of the text
  891. enclosed in CDATA marked sections are stored in <code class="xref py py-class docutils literal notranslate"><span class="pre">CDATASection</span></code> objects.
  892. These two interfaces are identical, but provide different values for the
  893. <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeType</span></code> attribute.</p>
  894. <p>These interfaces extend the <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> interface. They cannot have child
  895. nodes.</p>
  896. <dl class="py attribute">
  897. <dt class="sig sig-object py" id="xml.dom.Text.data">
  898. <span class="sig-prename descclassname"><span class="pre">Text.</span></span><span class="sig-name descname"><span class="pre">data</span></span><a class="headerlink" href="#xml.dom.Text.data" title="Link to this definition">¶</a></dt>
  899. <dd><p>The content of the text node as a string.</p>
  900. </dd></dl>
  901. <div class="admonition note">
  902. <p class="admonition-title">Note</p>
  903. <p>The use of a <code class="xref py py-class docutils literal notranslate"><span class="pre">CDATASection</span></code> node does not indicate that the node
  904. represents a complete CDATA marked section, only that the content of the node
  905. was part of a CDATA section. A single CDATA section may be represented by more
  906. than one node in the document tree. There is no way to determine whether two
  907. adjacent <code class="xref py py-class docutils literal notranslate"><span class="pre">CDATASection</span></code> nodes represent different CDATA marked sections.</p>
  908. </div>
  909. </section>
  910. <section id="processinginstruction-objects">
  911. <span id="dom-pi-objects"></span><h3>ProcessingInstruction Objects<a class="headerlink" href="#processinginstruction-objects" title="Link to this heading">¶</a></h3>
  912. <p>Represents a processing instruction in the XML document; this inherits from the
  913. <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> interface and cannot have child nodes.</p>
  914. <dl class="py attribute">
  915. <dt class="sig sig-object py" id="xml.dom.ProcessingInstruction.target">
  916. <span class="sig-prename descclassname"><span class="pre">ProcessingInstruction.</span></span><span class="sig-name descname"><span class="pre">target</span></span><a class="headerlink" href="#xml.dom.ProcessingInstruction.target" title="Link to this definition">¶</a></dt>
  917. <dd><p>The content of the processing instruction up to the first whitespace character.
  918. This is a read-only attribute.</p>
  919. </dd></dl>
  920. <dl class="py attribute">
  921. <dt class="sig sig-object py" id="xml.dom.ProcessingInstruction.data">
  922. <span class="sig-prename descclassname"><span class="pre">ProcessingInstruction.</span></span><span class="sig-name descname"><span class="pre">data</span></span><a class="headerlink" href="#xml.dom.ProcessingInstruction.data" title="Link to this definition">¶</a></dt>
  923. <dd><p>The content of the processing instruction following the first whitespace
  924. character.</p>
  925. </dd></dl>
  926. </section>
  927. <section id="exceptions">
  928. <span id="dom-exceptions"></span><h3>Exceptions<a class="headerlink" href="#exceptions" title="Link to this heading">¶</a></h3>
  929. <p>The DOM Level 2 recommendation defines a single exception, <a class="reference internal" href="#xml.dom.DOMException" title="xml.dom.DOMException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DOMException</span></code></a>,
  930. and a number of constants that allow applications to determine what sort of
  931. error occurred. <a class="reference internal" href="#xml.dom.DOMException" title="xml.dom.DOMException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DOMException</span></code></a> instances carry a <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
  932. that provides the appropriate value for the specific exception.</p>
  933. <p>The Python DOM interface provides the constants, but also expands the set of
  934. exceptions so that a specific exception exists for each of the exception codes
  935. defined by the DOM. The implementations must raise the appropriate specific
  936. exception, each of which carries the appropriate value for 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>
  937. attribute.</p>
  938. <dl class="py exception">
  939. <dt class="sig sig-object py" id="xml.dom.DOMException">
  940. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">DOMException</span></span><a class="headerlink" href="#xml.dom.DOMException" title="Link to this definition">¶</a></dt>
  941. <dd><p>Base exception class used for all specific DOM exceptions. This exception class
  942. cannot be directly instantiated.</p>
  943. </dd></dl>
  944. <dl class="py exception">
  945. <dt class="sig sig-object py" id="xml.dom.DomstringSizeErr">
  946. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">DomstringSizeErr</span></span><a class="headerlink" href="#xml.dom.DomstringSizeErr" title="Link to this definition">¶</a></dt>
  947. <dd><p>Raised when a specified range of text does not fit into a string. This is not
  948. known to be used in the Python DOM implementations, but may be received from DOM
  949. implementations not written in Python.</p>
  950. </dd></dl>
  951. <dl class="py exception">
  952. <dt class="sig sig-object py" id="xml.dom.HierarchyRequestErr">
  953. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">HierarchyRequestErr</span></span><a class="headerlink" href="#xml.dom.HierarchyRequestErr" title="Link to this definition">¶</a></dt>
  954. <dd><p>Raised when an attempt is made to insert a node where the node type is not
  955. allowed.</p>
  956. </dd></dl>
  957. <dl class="py exception">
  958. <dt class="sig sig-object py" id="xml.dom.IndexSizeErr">
  959. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">IndexSizeErr</span></span><a class="headerlink" href="#xml.dom.IndexSizeErr" title="Link to this definition">¶</a></dt>
  960. <dd><p>Raised when an index or size parameter to a method is negative or exceeds the
  961. allowed values.</p>
  962. </dd></dl>
  963. <dl class="py exception">
  964. <dt class="sig sig-object py" id="xml.dom.InuseAttributeErr">
  965. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">InuseAttributeErr</span></span><a class="headerlink" href="#xml.dom.InuseAttributeErr" title="Link to this definition">¶</a></dt>
  966. <dd><p>Raised when an attempt is made to insert an <code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> node that is already
  967. present elsewhere in the document.</p>
  968. </dd></dl>
  969. <dl class="py exception">
  970. <dt class="sig sig-object py" id="xml.dom.InvalidAccessErr">
  971. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">InvalidAccessErr</span></span><a class="headerlink" href="#xml.dom.InvalidAccessErr" title="Link to this definition">¶</a></dt>
  972. <dd><p>Raised if a parameter or an operation is not supported on the underlying object.</p>
  973. </dd></dl>
  974. <dl class="py exception">
  975. <dt class="sig sig-object py" id="xml.dom.InvalidCharacterErr">
  976. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">InvalidCharacterErr</span></span><a class="headerlink" href="#xml.dom.InvalidCharacterErr" title="Link to this definition">¶</a></dt>
  977. <dd><p>This exception is raised when a string parameter contains a character that is
  978. not permitted in the context it’s being used in by the XML 1.0 recommendation.
  979. For example, attempting to create an <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> node with a space in the
  980. element type name will cause this error to be raised.</p>
  981. </dd></dl>
  982. <dl class="py exception">
  983. <dt class="sig sig-object py" id="xml.dom.InvalidModificationErr">
  984. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">InvalidModificationErr</span></span><a class="headerlink" href="#xml.dom.InvalidModificationErr" title="Link to this definition">¶</a></dt>
  985. <dd><p>Raised when an attempt is made to modify the type of a node.</p>
  986. </dd></dl>
  987. <dl class="py exception">
  988. <dt class="sig sig-object py" id="xml.dom.InvalidStateErr">
  989. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">InvalidStateErr</span></span><a class="headerlink" href="#xml.dom.InvalidStateErr" title="Link to this definition">¶</a></dt>
  990. <dd><p>Raised when an attempt is made to use an object that is not defined or is no
  991. longer usable.</p>
  992. </dd></dl>
  993. <dl class="py exception">
  994. <dt class="sig sig-object py" id="xml.dom.NamespaceErr">
  995. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">NamespaceErr</span></span><a class="headerlink" href="#xml.dom.NamespaceErr" title="Link to this definition">¶</a></dt>
  996. <dd><p>If an attempt is made to change any object in a way that is not permitted with
  997. regard to the <a class="reference external" href="https://www.w3.org/TR/REC-xml-names/">Namespaces in XML</a>
  998. recommendation, this exception is raised.</p>
  999. </dd></dl>
  1000. <dl class="py exception">
  1001. <dt class="sig sig-object py" id="xml.dom.NotFoundErr">
  1002. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">NotFoundErr</span></span><a class="headerlink" href="#xml.dom.NotFoundErr" title="Link to this definition">¶</a></dt>
  1003. <dd><p>Exception when a node does not exist in the referenced context. For example,
  1004. <code class="xref py py-meth docutils literal notranslate"><span class="pre">NamedNodeMap.removeNamedItem()</span></code> will raise this if the node passed in does
  1005. not exist in the map.</p>
  1006. </dd></dl>
  1007. <dl class="py exception">
  1008. <dt class="sig sig-object py" id="xml.dom.NotSupportedErr">
  1009. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">NotSupportedErr</span></span><a class="headerlink" href="#xml.dom.NotSupportedErr" title="Link to this definition">¶</a></dt>
  1010. <dd><p>Raised when the implementation does not support the requested type of object or
  1011. operation.</p>
  1012. </dd></dl>
  1013. <dl class="py exception">
  1014. <dt class="sig sig-object py" id="xml.dom.NoDataAllowedErr">
  1015. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">NoDataAllowedErr</span></span><a class="headerlink" href="#xml.dom.NoDataAllowedErr" title="Link to this definition">¶</a></dt>
  1016. <dd><p>This is raised if data is specified for a node which does not support data.</p>
  1017. </dd></dl>
  1018. <dl class="py exception">
  1019. <dt class="sig sig-object py" id="xml.dom.NoModificationAllowedErr">
  1020. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">NoModificationAllowedErr</span></span><a class="headerlink" href="#xml.dom.NoModificationAllowedErr" title="Link to this definition">¶</a></dt>
  1021. <dd><p>Raised on attempts to modify an object where modifications are not allowed (such
  1022. as for read-only nodes).</p>
  1023. </dd></dl>
  1024. <dl class="py exception">
  1025. <dt class="sig sig-object py" id="xml.dom.SyntaxErr">
  1026. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">SyntaxErr</span></span><a class="headerlink" href="#xml.dom.SyntaxErr" title="Link to this definition">¶</a></dt>
  1027. <dd><p>Raised when an invalid or illegal string is specified.</p>
  1028. </dd></dl>
  1029. <dl class="py exception">
  1030. <dt class="sig sig-object py" id="xml.dom.WrongDocumentErr">
  1031. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.</span></span><span class="sig-name descname"><span class="pre">WrongDocumentErr</span></span><a class="headerlink" href="#xml.dom.WrongDocumentErr" title="Link to this definition">¶</a></dt>
  1032. <dd><p>Raised when a node is inserted in a different document than it currently belongs
  1033. to, and the implementation does not support migrating the node from one document
  1034. to the other.</p>
  1035. </dd></dl>
  1036. <p>The exception codes defined in the DOM recommendation map to the exceptions
  1037. described above according to this table:</p>
  1038. <table class="docutils align-default">
  1039. <thead>
  1040. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  1041. <th class="head"><p>Exception</p></th>
  1042. </tr>
  1043. </thead>
  1044. <tbody>
  1045. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">DOMSTRING_SIZE_ERR</span></code></p></td>
  1046. <td><p><a class="reference internal" href="#xml.dom.DomstringSizeErr" title="xml.dom.DomstringSizeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DomstringSizeErr</span></code></a></p></td>
  1047. </tr>
  1048. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">HIERARCHY_REQUEST_ERR</span></code></p></td>
  1049. <td><p><a class="reference internal" href="#xml.dom.HierarchyRequestErr" title="xml.dom.HierarchyRequestErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">HierarchyRequestErr</span></code></a></p></td>
  1050. </tr>
  1051. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">INDEX_SIZE_ERR</span></code></p></td>
  1052. <td><p><a class="reference internal" href="#xml.dom.IndexSizeErr" title="xml.dom.IndexSizeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexSizeErr</span></code></a></p></td>
  1053. </tr>
  1054. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">INUSE_ATTRIBUTE_ERR</span></code></p></td>
  1055. <td><p><a class="reference internal" href="#xml.dom.InuseAttributeErr" title="xml.dom.InuseAttributeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InuseAttributeErr</span></code></a></p></td>
  1056. </tr>
  1057. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_ACCESS_ERR</span></code></p></td>
  1058. <td><p><a class="reference internal" href="#xml.dom.InvalidAccessErr" title="xml.dom.InvalidAccessErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidAccessErr</span></code></a></p></td>
  1059. </tr>
  1060. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_CHARACTER_ERR</span></code></p></td>
  1061. <td><p><a class="reference internal" href="#xml.dom.InvalidCharacterErr" title="xml.dom.InvalidCharacterErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidCharacterErr</span></code></a></p></td>
  1062. </tr>
  1063. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_MODIFICATION_ERR</span></code></p></td>
  1064. <td><p><a class="reference internal" href="#xml.dom.InvalidModificationErr" title="xml.dom.InvalidModificationErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidModificationErr</span></code></a></p></td>
  1065. </tr>
  1066. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_STATE_ERR</span></code></p></td>
  1067. <td><p><a class="reference internal" href="#xml.dom.InvalidStateErr" title="xml.dom.InvalidStateErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidStateErr</span></code></a></p></td>
  1068. </tr>
  1069. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NAMESPACE_ERR</span></code></p></td>
  1070. <td><p><a class="reference internal" href="#xml.dom.NamespaceErr" title="xml.dom.NamespaceErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NamespaceErr</span></code></a></p></td>
  1071. </tr>
  1072. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NOT_FOUND_ERR</span></code></p></td>
  1073. <td><p><a class="reference internal" href="#xml.dom.NotFoundErr" title="xml.dom.NotFoundErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFoundErr</span></code></a></p></td>
  1074. </tr>
  1075. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NOT_SUPPORTED_ERR</span></code></p></td>
  1076. <td><p><a class="reference internal" href="#xml.dom.NotSupportedErr" title="xml.dom.NotSupportedErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotSupportedErr</span></code></a></p></td>
  1077. </tr>
  1078. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NO_DATA_ALLOWED_ERR</span></code></p></td>
  1079. <td><p><a class="reference internal" href="#xml.dom.NoDataAllowedErr" title="xml.dom.NoDataAllowedErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NoDataAllowedErr</span></code></a></p></td>
  1080. </tr>
  1081. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NO_MODIFICATION_ALLOWED_ERR</span></code></p></td>
  1082. <td><p><a class="reference internal" href="#xml.dom.NoModificationAllowedErr" title="xml.dom.NoModificationAllowedErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NoModificationAllowedErr</span></code></a></p></td>
  1083. </tr>
  1084. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">SYNTAX_ERR</span></code></p></td>
  1085. <td><p><a class="reference internal" href="#xml.dom.SyntaxErr" title="xml.dom.SyntaxErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxErr</span></code></a></p></td>
  1086. </tr>
  1087. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">WRONG_DOCUMENT_ERR</span></code></p></td>
  1088. <td><p><a class="reference internal" href="#xml.dom.WrongDocumentErr" title="xml.dom.WrongDocumentErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WrongDocumentErr</span></code></a></p></td>
  1089. </tr>
  1090. </tbody>
  1091. </table>
  1092. </section>
  1093. </section>
  1094. <section id="conformance">
  1095. <span id="dom-conformance"></span><h2>Conformance<a class="headerlink" href="#conformance" title="Link to this heading">¶</a></h2>
  1096. <p>This section describes the conformance requirements and relationships between
  1097. the Python DOM API, the W3C DOM recommendations, and the OMG IDL mapping for
  1098. Python.</p>
  1099. <section id="type-mapping">
  1100. <span id="dom-type-mapping"></span><h3>Type Mapping<a class="headerlink" href="#type-mapping" title="Link to this heading">¶</a></h3>
  1101. <p>The IDL types used in the DOM specification are mapped to Python types
  1102. according to the following table.</p>
  1103. <table class="docutils align-default">
  1104. <thead>
  1105. <tr class="row-odd"><th class="head"><p>IDL Type</p></th>
  1106. <th class="head"><p>Python Type</p></th>
  1107. </tr>
  1108. </thead>
  1109. <tbody>
  1110. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">boolean</span></code></p></td>
  1111. <td><p><code class="docutils literal notranslate"><span class="pre">bool</span></code> or <code class="docutils literal notranslate"><span class="pre">int</span></code></p></td>
  1112. </tr>
  1113. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">int</span></code></p></td>
  1114. <td><p><code class="docutils literal notranslate"><span class="pre">int</span></code></p></td>
  1115. </tr>
  1116. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">long</span> <span class="pre">int</span></code></p></td>
  1117. <td><p><code class="docutils literal notranslate"><span class="pre">int</span></code></p></td>
  1118. </tr>
  1119. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">unsigned</span> <span class="pre">int</span></code></p></td>
  1120. <td><p><code class="docutils literal notranslate"><span class="pre">int</span></code></p></td>
  1121. </tr>
  1122. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">DOMString</span></code></p></td>
  1123. <td><p><code class="docutils literal notranslate"><span class="pre">str</span></code> or <code class="docutils literal notranslate"><span class="pre">bytes</span></code></p></td>
  1124. </tr>
  1125. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">null</span></code></p></td>
  1126. <td><p><code class="docutils literal notranslate"><span class="pre">None</span></code></p></td>
  1127. </tr>
  1128. </tbody>
  1129. </table>
  1130. </section>
  1131. <section id="accessor-methods">
  1132. <span id="dom-accessor-methods"></span><h3>Accessor Methods<a class="headerlink" href="#accessor-methods" title="Link to this heading">¶</a></h3>
  1133. <p>The mapping from OMG IDL to Python defines accessor functions for IDL
  1134. <code class="docutils literal notranslate"><span class="pre">attribute</span></code> declarations in much the way the Java mapping does.
  1135. Mapping the IDL declarations</p>
  1136. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">readonly</span> <span class="n">attribute</span> <span class="n">string</span> <span class="n">someValue</span><span class="p">;</span>
  1137. <span class="n">attribute</span> <span class="n">string</span> <span class="n">anotherValue</span><span class="p">;</span>
  1138. </pre></div>
  1139. </div>
  1140. <p>yields three accessor functions: a “get” method for <code class="xref py py-attr docutils literal notranslate"><span class="pre">someValue</span></code>
  1141. (<code class="xref py py-meth docutils literal notranslate"><span class="pre">_get_someValue()</span></code>), and “get” and “set” methods for <code class="xref py py-attr docutils literal notranslate"><span class="pre">anotherValue</span></code>
  1142. (<code class="xref py py-meth docutils literal notranslate"><span class="pre">_get_anotherValue()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">_set_anotherValue()</span></code>). The mapping, in
  1143. particular, does not require that the IDL attributes are accessible as normal
  1144. Python attributes: <code class="docutils literal notranslate"><span class="pre">object.someValue</span></code> is <em>not</em> required to work, and may
  1145. raise an <a class="reference internal" href="exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>.</p>
  1146. <p>The Python DOM API, however, <em>does</em> require that normal attribute access work.
  1147. This means that the typical surrogates generated by Python IDL compilers are not
  1148. likely to work, and wrapper objects may be needed on the client if the DOM
  1149. objects are accessed via CORBA. While this does require some additional
  1150. consideration for CORBA DOM clients, the implementers with experience using DOM
  1151. over CORBA from Python do not consider this a problem. Attributes that are
  1152. declared <code class="docutils literal notranslate"><span class="pre">readonly</span></code> may not restrict write access in all DOM
  1153. implementations.</p>
  1154. <p>In the Python DOM API, accessor functions are not required. If provided, they
  1155. should take the form defined by the Python IDL mapping, but these methods are
  1156. considered unnecessary since the attributes are accessible directly from Python.
  1157. “Set” accessors should never be provided for <code class="docutils literal notranslate"><span class="pre">readonly</span></code> attributes.</p>
  1158. <p>The IDL definitions do not fully embody the requirements of the W3C DOM API,
  1159. such as the notion of certain objects, such as the return value of
  1160. <code class="xref py py-meth docutils literal notranslate"><span class="pre">getElementsByTagName()</span></code>, being “live”. The Python DOM API does not require
  1161. implementations to enforce such requirements.</p>
  1162. </section>
  1163. </section>
  1164. </section>
  1165. <div class="clearer"></div>
  1166. </div>
  1167. </div>
  1168. </div>
  1169. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  1170. <div class="sphinxsidebarwrapper">
  1171. <div>
  1172. <h3><a href="../contents.html">Table of Contents</a></h3>
  1173. <ul>
  1174. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code> — The Document Object Model API</a><ul>
  1175. <li><a class="reference internal" href="#module-contents">Module Contents</a></li>
  1176. <li><a class="reference internal" href="#objects-in-the-dom">Objects in the DOM</a><ul>
  1177. <li><a class="reference internal" href="#domimplementation-objects">DOMImplementation Objects</a></li>
  1178. <li><a class="reference internal" href="#node-objects">Node Objects</a></li>
  1179. <li><a class="reference internal" href="#nodelist-objects">NodeList Objects</a></li>
  1180. <li><a class="reference internal" href="#documenttype-objects">DocumentType Objects</a></li>
  1181. <li><a class="reference internal" href="#document-objects">Document Objects</a></li>
  1182. <li><a class="reference internal" href="#element-objects">Element Objects</a></li>
  1183. <li><a class="reference internal" href="#attr-objects">Attr Objects</a></li>
  1184. <li><a class="reference internal" href="#namednodemap-objects">NamedNodeMap Objects</a></li>
  1185. <li><a class="reference internal" href="#comment-objects">Comment Objects</a></li>
  1186. <li><a class="reference internal" href="#text-and-cdatasection-objects">Text and CDATASection Objects</a></li>
  1187. <li><a class="reference internal" href="#processinginstruction-objects">ProcessingInstruction Objects</a></li>
  1188. <li><a class="reference internal" href="#exceptions">Exceptions</a></li>
  1189. </ul>
  1190. </li>
  1191. <li><a class="reference internal" href="#conformance">Conformance</a><ul>
  1192. <li><a class="reference internal" href="#type-mapping">Type Mapping</a></li>
  1193. <li><a class="reference internal" href="#accessor-methods">Accessor Methods</a></li>
  1194. </ul>
  1195. </li>
  1196. </ul>
  1197. </li>
  1198. </ul>
  1199. </div>
  1200. <div>
  1201. <h4>Previous topic</h4>
  1202. <p class="topless"><a href="xml.etree.elementtree.html"
  1203. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code> — The ElementTree XML API</a></p>
  1204. </div>
  1205. <div>
  1206. <h4>Next topic</h4>
  1207. <p class="topless"><a href="xml.dom.minidom.html"
  1208. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code> — Minimal DOM implementation</a></p>
  1209. </div>
  1210. <div role="note" aria-label="source link">
  1211. <h3>This Page</h3>
  1212. <ul class="this-page-menu">
  1213. <li><a href="../bugs.html">Report a Bug</a></li>
  1214. <li>
  1215. <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.dom.rst"
  1216. rel="nofollow">Show Source
  1217. </a>
  1218. </li>
  1219. </ul>
  1220. </div>
  1221. </div>
  1222. <div id="sidebarbutton" title="Collapse sidebar">
  1223. <span>«</span>
  1224. </div>
  1225. </div>
  1226. <div class="clearer"></div>
  1227. </div>
  1228. <div class="related" role="navigation" aria-label="related navigation">
  1229. <h3>Navigation</h3>
  1230. <ul>
  1231. <li class="right" style="margin-right: 10px">
  1232. <a href="../genindex.html" title="General Index"
  1233. >index</a></li>
  1234. <li class="right" >
  1235. <a href="../py-modindex.html" title="Python Module Index"
  1236. >modules</a> |</li>
  1237. <li class="right" >
  1238. <a href="xml.dom.minidom.html" title="xml.dom.minidom — Minimal DOM implementation"
  1239. >next</a> |</li>
  1240. <li class="right" >
  1241. <a href="xml.etree.elementtree.html" title="xml.etree.ElementTree — The ElementTree XML API"
  1242. >previous</a> |</li>
  1243. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  1244. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  1245. <li class="switchers">
  1246. <div class="language_switcher_placeholder"></div>
  1247. <div class="version_switcher_placeholder"></div>
  1248. </li>
  1249. <li>
  1250. </li>
  1251. <li id="cpython-language-and-version">
  1252. <a href="../index.html">3.12.3 Documentation</a> &#187;
  1253. </li>
  1254. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  1255. <li class="nav-item nav-item-2"><a href="markup.html" >Structured Markup Processing Tools</a> &#187;</li>
  1256. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code> — The Document Object Model API</a></li>
  1257. <li class="right">
  1258. <div class="inline-search" role="search">
  1259. <form class="inline-search" action="../search.html" method="get">
  1260. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  1261. <input type="submit" value="Go" />
  1262. </form>
  1263. </div>
  1264. |
  1265. </li>
  1266. <li class="right">
  1267. <label class="theme-selector-label">
  1268. Theme
  1269. <select class="theme-selector" oninput="activateTheme(this.value)">
  1270. <option value="auto" selected>Auto</option>
  1271. <option value="light">Light</option>
  1272. <option value="dark">Dark</option>
  1273. </select>
  1274. </label> |</li>
  1275. </ul>
  1276. </div>
  1277. <div class="footer">
  1278. &copy;
  1279. <a href="../copyright.html">
  1280. Copyright
  1281. </a>
  1282. 2001-2024, Python Software Foundation.
  1283. <br />
  1284. This page is licensed under the Python Software Foundation License Version 2.
  1285. <br />
  1286. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  1287. <br />
  1288. See <a href="/license.html">History and License</a> for more information.<br />
  1289. <br />
  1290. The Python Software Foundation is a non-profit corporation.
  1291. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  1292. <br />
  1293. <br />
  1294. Last updated on Apr 09, 2024 (13:47 UTC).
  1295. <a href="/bugs.html">Found a bug</a>?
  1296. <br />
  1297. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1298. </div>
  1299. </body>
  1300. </html>
上海开阖软件有限公司 沪ICP备12045867号-1