Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
xml.dom.pulldom.html510 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="xml.dom.pulldom — Support for building partial DOM trees" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/xml.dom.pulldom.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/xml/dom/pulldom.py The xml.dom.pulldom module provides a “pull parser” which can also be asked to produce DOM-accessible fragments of the document where necessary. The basic concep..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_xml.dom.pulldom_a577e061.png" />15<meta property="og:image:alt" content="Source code: Lib/xml/dom/pulldom.py The xml.dom.pulldom module provides a “pull parser” which can also be asked to produce DOM-accessible fragments of the document where necessary. The basic concep..." />16<meta name="description" content="Source code: Lib/xml/dom/pulldom.py The xml.dom.pulldom module provides a “pull parser” which can also be asked to produce DOM-accessible fragments of the document where necessary. The basic concep..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>xml.dom.pulldom — Support for building partial DOM trees &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="xml.sax — Support for SAX2 parsers" href="xml.sax.html" />43    <link rel="prev" title="xml.dom.minidom — Minimal DOM implementation" href="xml.dom.minidom.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/xml.dom.pulldom.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> — Support for building partial DOM trees</a><ul>108<li><a class="reference internal" href="#domeventstream-objects">DOMEventStream Objects</a></li>109</ul>110</li>111</ul>112 113  </div>114  <div>115    <h4>Previous topic</h4>116    <p class="topless"><a href="xml.dom.minidom.html"117                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code> — Minimal DOM implementation</a></p>118  </div>119  <div>120    <h4>Next topic</h4>121    <p class="topless"><a href="xml.sax.html"122                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a></p>123  </div>124  <script>125    document.addEventListener('DOMContentLoaded', () => {126        const title = document.querySelector('meta[property="og:title"]').content;127        const elements = document.querySelectorAll('.improvepage');128        const pageurl = window.location.href.split('?')[0];129        elements.forEach(element => {130            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));131            url.searchParams.set('pagetitle', title);132            url.searchParams.set('pageurl', pageurl);133            url.searchParams.set('pagesource', "library/xml.dom.pulldom.rst");134            element.href = url.toString();135        });136    });137  </script>138  <div role="note" aria-label="source link">139    <h3>This page</h3>140    <ul class="this-page-menu">141      <li><a href="../bugs.html">Report a bug</a></li>142      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>143      <li>144        <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.dom.pulldom.rst?plain=1"145            rel="nofollow">Show source146        </a>147      </li>148      149    </ul>150  </div>151        </nav>152    </div>153</div>154 155  156    <div class="related" role="navigation" aria-label="Related">157      <h3>Navigation</h3>158      <ul>159        <li class="right" style="margin-right: 10px">160          <a href="../genindex.html" title="General Index"161             accesskey="I">index</a></li>162        <li class="right" >163          <a href="../py-modindex.html" title="Python Module Index"164             >modules</a> |</li>165        <li class="right" >166          <a href="xml.sax.html" title="xml.sax — Support for SAX2 parsers"167             accesskey="N">next</a> |</li>168        <li class="right" >169          <a href="xml.dom.minidom.html" title="xml.dom.minidom — Minimal DOM implementation"170             accesskey="P">previous</a> |</li>171 172          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>173          <li><a href="https://www.python.org/">Python</a> &#187;</li>174          <li class="switchers">175            <div class="language_switcher_placeholder"></div>176            <div class="version_switcher_placeholder"></div>177          </li>178          <li>179              180          </li>181    <li id="cpython-language-and-version">182      <a href="../index.html">3.15.0a6 Documentation</a> &#187;183    </li>184 185          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>186          <li class="nav-item nav-item-2"><a href="markup.html" accesskey="U">Structured Markup Processing Tools</a> &#187;</li>187        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> — Support for building partial DOM trees</a></li>188                <li class="right">189                    190 191    <div class="inline-search" role="search">192        <form class="inline-search" action="../search.html" method="get">193          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">194          <input type="submit" value="Go">195        </form>196    </div>197                     |198                </li>199            <li class="right">200<label class="theme-selector-label">201    Theme202    <select class="theme-selector" oninput="activateTheme(this.value)">203        <option value="auto" selected>Auto</option>204        <option value="light">Light</option>205        <option value="dark">Dark</option>206    </select>207</label> |</li>208            209      </ul>210    </div>    211 212    <div class="document">213      <div class="documentwrapper">214        <div class="bodywrapper">215          <div class="body" role="main">216            217  <section id="module-xml.dom.pulldom">218<span id="xml-dom-pulldom-support-for-building-partial-dom-trees"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> — Support for building partial DOM trees<a class="headerlink" href="#module-xml.dom.pulldom" title="Link to this heading">¶</a></h1>219<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/xml/dom/pulldom.py">Lib/xml/dom/pulldom.py</a></p>220<hr class="docutils" />221<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> module provides a “pull parser” which can also be222asked to produce DOM-accessible fragments of the document where necessary. The223basic concept involves pulling “events” from a stream of incoming XML and224processing them. In contrast to SAX which also employs an event-driven225processing model together with callbacks, the user of a pull parser is226responsible for explicitly pulling events from the stream, looping over those227events until either processing is finished or an error condition occurs.</p>228<div class="admonition note">229<p class="admonition-title">Note</p>230<p>If you need to parse untrusted or unauthenticated data, see231<a class="reference internal" href="xml.html#xml-security"><span class="std std-ref">XML security</span></a>.</p>232</div>233<div class="versionchanged">234<p><span class="versionmodified changed">Changed in version 3.7.1: </span>The SAX parser no longer processes general external entities by default to235increase security by default. To enable processing of external entities,236pass a custom parser instance in:</p>237<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">xml.dom.pulldom</span><span class="w"> </span><span class="kn">import</span> <span class="n">parse</span>238<span class="kn">from</span><span class="w"> </span><span class="nn">xml.sax</span><span class="w"> </span><span class="kn">import</span> <span class="n">make_parser</span>239<span class="kn">from</span><span class="w"> </span><span class="nn">xml.sax.handler</span><span class="w"> </span><span class="kn">import</span> <span class="n">feature_external_ges</span>240 241<span class="n">parser</span> <span class="o">=</span> <span class="n">make_parser</span><span class="p">()</span>242<span class="n">parser</span><span class="o">.</span><span class="n">setFeature</span><span class="p">(</span><span class="n">feature_external_ges</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>243<span class="n">parse</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">parser</span><span class="o">=</span><span class="n">parser</span><span class="p">)</span>244</pre></div>245</div>246</div>247<p>Example:</p>248<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">xml.dom</span><span class="w"> </span><span class="kn">import</span> <span class="n">pulldom</span>249 250<span class="n">doc</span> <span class="o">=</span> <span class="n">pulldom</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s1">&#39;sales_items.xml&#39;</span><span class="p">)</span>251<span class="k">for</span> <span class="n">event</span><span class="p">,</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">doc</span><span class="p">:</span>252    <span class="k">if</span> <span class="n">event</span> <span class="o">==</span> <span class="n">pulldom</span><span class="o">.</span><span class="n">START_ELEMENT</span> <span class="ow">and</span> <span class="n">node</span><span class="o">.</span><span class="n">tagName</span> <span class="o">==</span> <span class="s1">&#39;item&#39;</span><span class="p">:</span>253        <span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">getAttribute</span><span class="p">(</span><span class="s1">&#39;price&#39;</span><span class="p">))</span> <span class="o">&gt;</span> <span class="mi">50</span><span class="p">:</span>254            <span class="n">doc</span><span class="o">.</span><span class="n">expandNode</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>255            <span class="nb">print</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">toxml</span><span class="p">())</span>256</pre></div>257</div>258<p><code class="docutils literal notranslate"><span class="pre">event</span></code> is a constant and can be one of:</p>259<ul class="simple">260<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">START_ELEMENT</span></code></p></li>261<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">END_ELEMENT</span></code></p></li>262<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">COMMENT</span></code></p></li>263<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">START_DOCUMENT</span></code></p></li>264<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">END_DOCUMENT</span></code></p></li>265<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">CHARACTERS</span></code></p></li>266<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">PROCESSING_INSTRUCTION</span></code></p></li>267<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">IGNORABLE_WHITESPACE</span></code></p></li>268</ul>269<p><code class="docutils literal notranslate"><span class="pre">node</span></code> is an object of type <code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.minidom.Document</span></code>,270<code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.minidom.Element</span></code> or <code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.minidom.Text</span></code>.</p>271<p>Since the document is treated as a “flat” stream of events, the document “tree”272is implicitly traversed and the desired elements are found regardless of their273depth in the tree. In other words, one does not need to consider hierarchical274issues such as recursive searching of the document nodes, although if the275context of elements were important, one would either need to maintain some276context-related state (i.e. remembering where one is in the document at any277given point) or to make use of the <a class="reference internal" href="#xml.dom.pulldom.DOMEventStream.expandNode" title="xml.dom.pulldom.DOMEventStream.expandNode"><code class="xref py py-func docutils literal notranslate"><span class="pre">DOMEventStream.expandNode()</span></code></a> method278and switch to DOM-related processing.</p>279<dl class="py class">280<dt class="sig sig-object py" id="xml.dom.pulldom.PullDOM">281<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.pulldom.</span></span><span class="sig-name descname"><span class="pre">PullDOM</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">documentFactory</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.PullDOM" title="Link to this definition">¶</a></dt>282<dd><p>Subclass of <a class="reference internal" href="xml.sax.handler.html#xml.sax.handler.ContentHandler" title="xml.sax.handler.ContentHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.sax.handler.ContentHandler</span></code></a>.</p>283</dd></dl>284 285<dl class="py class">286<dt class="sig sig-object py" id="xml.dom.pulldom.SAX2DOM">287<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.pulldom.</span></span><span class="sig-name descname"><span class="pre">SAX2DOM</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">documentFactory</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.SAX2DOM" title="Link to this definition">¶</a></dt>288<dd><p>Subclass of <a class="reference internal" href="xml.sax.handler.html#xml.sax.handler.ContentHandler" title="xml.sax.handler.ContentHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.sax.handler.ContentHandler</span></code></a>.</p>289</dd></dl>290 291<dl class="py function">292<dt class="sig sig-object py" id="xml.dom.pulldom.parse">293<span class="sig-prename descclassname"><span class="pre">xml.dom.pulldom.</span></span><span class="sig-name descname"><span class="pre">parse</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stream_or_string</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parser</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">bufsize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.parse" title="Link to this definition">¶</a></dt>294<dd><p>Return a <a class="reference internal" href="#xml.dom.pulldom.DOMEventStream" title="xml.dom.pulldom.DOMEventStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">DOMEventStream</span></code></a> from the given input. <em>stream_or_string</em> may be295either a file name, or a file-like object. <em>parser</em>, if given, must be an296<a class="reference internal" href="xml.sax.reader.html#xml.sax.xmlreader.XMLReader" title="xml.sax.xmlreader.XMLReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLReader</span></code></a> object. This function will change the297document handler of the298parser and activate namespace support; other parser configuration (like299setting an entity resolver) must have been done in advance.</p>300</dd></dl>301 302<p>If you have XML in a string, you can use the <a class="reference internal" href="#xml.dom.pulldom.parseString" title="xml.dom.pulldom.parseString"><code class="xref py py-func docutils literal notranslate"><span class="pre">parseString()</span></code></a> function instead:</p>303<dl class="py function">304<dt class="sig sig-object py" id="xml.dom.pulldom.parseString">305<span class="sig-prename descclassname"><span class="pre">xml.dom.pulldom.</span></span><span class="sig-name descname"><span class="pre">parseString</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parser</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.parseString" title="Link to this definition">¶</a></dt>306<dd><p>Return a <a class="reference internal" href="#xml.dom.pulldom.DOMEventStream" title="xml.dom.pulldom.DOMEventStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">DOMEventStream</span></code></a> that represents the (Unicode) <em>string</em>.</p>307</dd></dl>308 309<dl class="py data">310<dt class="sig sig-object py" id="xml.dom.pulldom.default_bufsize">311<span class="sig-prename descclassname"><span class="pre">xml.dom.pulldom.</span></span><span class="sig-name descname"><span class="pre">default_bufsize</span></span><a class="headerlink" href="#xml.dom.pulldom.default_bufsize" title="Link to this definition">¶</a></dt>312<dd><p>Default value for the <em>bufsize</em> parameter to <a class="reference internal" href="#xml.dom.pulldom.parse" title="xml.dom.pulldom.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse()</span></code></a>.</p>313<p>The value of this variable can be changed before calling <a class="reference internal" href="#xml.dom.pulldom.parse" title="xml.dom.pulldom.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse()</span></code></a> and314the new value will take effect.</p>315</dd></dl>316 317<section id="domeventstream-objects">318<span id="id1"></span><h2>DOMEventStream Objects<a class="headerlink" href="#domeventstream-objects" title="Link to this heading">¶</a></h2>319<dl class="py class">320<dt class="sig sig-object py" id="xml.dom.pulldom.DOMEventStream">321<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">xml.dom.pulldom.</span></span><span class="sig-name descname"><span class="pre">DOMEventStream</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stream</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parser</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bufsize</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.DOMEventStream" title="Link to this definition">¶</a></dt>322<dd><div class="versionchanged">323<p><span class="versionmodified changed">Changed in version 3.11: </span>Support for <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> method has been removed.</p>324</div>325<dl class="py method">326<dt class="sig sig-object py" id="xml.dom.pulldom.DOMEventStream.getEvent">327<span class="sig-name descname"><span class="pre">getEvent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.DOMEventStream.getEvent" title="Link to this definition">¶</a></dt>328<dd><p>Return a tuple containing <em>event</em> and the current <em>node</em> as329<code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.minidom.Document</span></code> if event equals <code class="xref py py-data docutils literal notranslate"><span class="pre">START_DOCUMENT</span></code>,330<code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.minidom.Element</span></code> if event equals <code class="xref py py-data docutils literal notranslate"><span class="pre">START_ELEMENT</span></code> or331<code class="xref py py-data docutils literal notranslate"><span class="pre">END_ELEMENT</span></code> or <code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.minidom.Text</span></code> if event equals332<code class="xref py py-data docutils literal notranslate"><span class="pre">CHARACTERS</span></code>.333The current node does not contain information about its children, unless334<a class="reference internal" href="#xml.dom.pulldom.DOMEventStream.expandNode" title="xml.dom.pulldom.DOMEventStream.expandNode"><code class="xref py py-func docutils literal notranslate"><span class="pre">expandNode()</span></code></a> is called.</p>335</dd></dl>336 337<dl class="py method">338<dt class="sig sig-object py" id="xml.dom.pulldom.DOMEventStream.expandNode">339<span class="sig-name descname"><span class="pre">expandNode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">node</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.DOMEventStream.expandNode" title="Link to this definition">¶</a></dt>340<dd><p>Expands all children of <em>node</em> into <em>node</em>. Example:</p>341<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">xml.dom</span><span class="w"> </span><span class="kn">import</span> <span class="n">pulldom</span>342 343<span class="n">xml</span> <span class="o">=</span> <span class="s1">&#39;&lt;html&gt;&lt;title&gt;Foo&lt;/title&gt; &lt;p&gt;Some text &lt;div&gt;and more&lt;/div&gt;&lt;/p&gt; &lt;/html&gt;&#39;</span>344<span class="n">doc</span> <span class="o">=</span> <span class="n">pulldom</span><span class="o">.</span><span class="n">parseString</span><span class="p">(</span><span class="n">xml</span><span class="p">)</span>345<span class="k">for</span> <span class="n">event</span><span class="p">,</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">doc</span><span class="p">:</span>346    <span class="k">if</span> <span class="n">event</span> <span class="o">==</span> <span class="n">pulldom</span><span class="o">.</span><span class="n">START_ELEMENT</span> <span class="ow">and</span> <span class="n">node</span><span class="o">.</span><span class="n">tagName</span> <span class="o">==</span> <span class="s1">&#39;p&#39;</span><span class="p">:</span>347        <span class="c1"># Following statement only prints &#39;&lt;p/&gt;&#39;</span>348        <span class="nb">print</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">toxml</span><span class="p">())</span>349        <span class="n">doc</span><span class="o">.</span><span class="n">expandNode</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>350        <span class="c1"># Following statement prints node with all its children &#39;&lt;p&gt;Some text &lt;div&gt;and more&lt;/div&gt;&lt;/p&gt;&#39;</span>351        <span class="nb">print</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">toxml</span><span class="p">())</span>352</pre></div>353</div>354</dd></dl>355 356<dl class="py method">357<dt class="sig sig-object py" id="xml.dom.pulldom.DOMEventStream.reset">358<span class="sig-name descname"><span class="pre">reset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.pulldom.DOMEventStream.reset" title="Link to this definition">¶</a></dt>359<dd></dd></dl>360 361</dd></dl>362 363</section>364</section>365 366 367            <div class="clearer"></div>368          </div>369        </div>370      </div>371      <div class="sphinxsidebar" role="navigation" aria-label="Main">372        <div class="sphinxsidebarwrapper">373  <div>374    <h3><a href="../contents.html">Table of Contents</a></h3>375    <ul>376<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> — Support for building partial DOM trees</a><ul>377<li><a class="reference internal" href="#domeventstream-objects">DOMEventStream Objects</a></li>378</ul>379</li>380</ul>381 382  </div>383  <div>384    <h4>Previous topic</h4>385    <p class="topless"><a href="xml.dom.minidom.html"386                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code> — Minimal DOM implementation</a></p>387  </div>388  <div>389    <h4>Next topic</h4>390    <p class="topless"><a href="xml.sax.html"391                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code> — Support for SAX2 parsers</a></p>392  </div>393  <script>394    document.addEventListener('DOMContentLoaded', () => {395        const title = document.querySelector('meta[property="og:title"]').content;396        const elements = document.querySelectorAll('.improvepage');397        const pageurl = window.location.href.split('?')[0];398        elements.forEach(element => {399            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));400            url.searchParams.set('pagetitle', title);401            url.searchParams.set('pageurl', pageurl);402            url.searchParams.set('pagesource', "library/xml.dom.pulldom.rst");403            element.href = url.toString();404        });405    });406  </script>407  <div role="note" aria-label="source link">408    <h3>This page</h3>409    <ul class="this-page-menu">410      <li><a href="../bugs.html">Report a bug</a></li>411      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>412      <li>413        <a href="https://github.com/python/cpython/blob/main/Doc/library/xml.dom.pulldom.rst?plain=1"414            rel="nofollow">Show source415        </a>416      </li>417      418    </ul>419  </div>420        </div>421<div id="sidebarbutton" title="Collapse sidebar">422<span>«</span>423</div>424 425      </div>426      <div class="clearer"></div>427    </div>  428    <div class="related" role="navigation" aria-label="Related">429      <h3>Navigation</h3>430      <ul>431        <li class="right" style="margin-right: 10px">432          <a href="../genindex.html" title="General Index"433             >index</a></li>434        <li class="right" >435          <a href="../py-modindex.html" title="Python Module Index"436             >modules</a> |</li>437        <li class="right" >438          <a href="xml.sax.html" title="xml.sax — Support for SAX2 parsers"439             >next</a> |</li>440        <li class="right" >441          <a href="xml.dom.minidom.html" title="xml.dom.minidom — Minimal DOM implementation"442             >previous</a> |</li>443 444          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>445          <li><a href="https://www.python.org/">Python</a> &#187;</li>446          <li class="switchers">447            <div class="language_switcher_placeholder"></div>448            <div class="version_switcher_placeholder"></div>449          </li>450          <li>451              452          </li>453    <li id="cpython-language-and-version">454      <a href="../index.html">3.15.0a6 Documentation</a> &#187;455    </li>456 457          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>458          <li class="nav-item nav-item-2"><a href="markup.html" >Structured Markup Processing Tools</a> &#187;</li>459        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.pulldom</span></code> — Support for building partial DOM trees</a></li>460                <li class="right">461                    462 463    <div class="inline-search" role="search">464        <form class="inline-search" action="../search.html" method="get">465          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">466          <input type="submit" value="Go">467        </form>468    </div>469                     |470                </li>471            <li class="right">472<label class="theme-selector-label">473    Theme474    <select class="theme-selector" oninput="activateTheme(this.value)">475        <option value="auto" selected>Auto</option>476        <option value="light">Light</option>477        <option value="dark">Dark</option>478    </select>479</label> |</li>480            481      </ul>482    </div>  483    <div class="footer">484    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.485    <br>486    This page is licensed under the Python Software Foundation License Version 2.487    <br>488    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.489    <br>490    491      See <a href="/license.html">History and License</a> for more information.<br>492    493    494    <br>495 496    The Python Software Foundation is a non-profit corporation.497<a href="https://www.python.org/psf/donations/">Please donate.</a>498<br>499    <br>500      Last updated on Mar 10, 2026 (08:58 UTC).501    502      <a href="/bugs.html">Found a bug</a>?503    504    <br>505 506    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.507    </div>508 509  </body>510</html>