<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](xml.sax.xhtml "xml.sax --- Support for SAX2 parsers") | - [上一頁](xml.dom.minidom.xhtml "xml.dom.minidom --- Minimal DOM implementation") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [結構化標記處理工具](markup.xhtml) ? - $('.inline-search').show(0); | # [`xml.dom.pulldom`](#module-xml.dom.pulldom "xml.dom.pulldom: Support for building partial DOM trees from SAX events.") --- Support for building partial DOM trees **Source code:** [Lib/xml/dom/pulldom.py](https://github.com/python/cpython/tree/3.7/Lib/xml/dom/pulldom.py) \[https://github.com/python/cpython/tree/3.7/Lib/xml/dom/pulldom.py\] - - - - - - The [`xml.dom.pulldom`](#module-xml.dom.pulldom "xml.dom.pulldom: Support for building partial DOM trees from SAX events.") module provides a "pull parser" which can also be asked to produce DOM-accessible fragments of the document where necessary. The basic concept involves pulling "events" from a stream of incoming XML and processing them. In contrast to SAX which also employs an event-driven processing model together with callbacks, the user of a pull parser is responsible for explicitly pulling events from the stream, looping over those events until either processing is finished or an error condition occurs. 警告 The [`xml.dom.pulldom`](#module-xml.dom.pulldom "xml.dom.pulldom: Support for building partial DOM trees from SAX events.") module is not secure against maliciously constructed data. If you need to parse untrusted or unauthenticated data see [XML 漏洞](xml.xhtml#xml-vulnerabilities). 在 3.7.1 版更改: The SAX parser no longer processes general external entities by default to increase security by default. To enable processing of external entities, pass a custom parser instance in: ``` from xml.dom.pulldom import parse from xml.sax import make_parser from xml.sax.handler import feature_external_ges parser = make_parser() parser.setFeature(feature_external_ges, True) parse(filename, parser=parser) ``` 示例: ``` from xml.dom import pulldom doc = pulldom.parse('sales_items.xml') for event, node in doc: if event == pulldom.START_ELEMENT and node.tagName == 'item': if int(node.getAttribute('price')) > 50: doc.expandNode(node) print(node.toxml()) ``` `event` is a constant and can be one of: - `START_ELEMENT` - `END_ELEMENT` - `COMMENT` - `START_DOCUMENT` - `END_DOCUMENT` - `CHARACTERS` - `PROCESSING_INSTRUCTION` - `IGNORABLE_WHITESPACE` `node` is an object of type `xml.dom.minidom.Document`, `xml.dom.minidom.Element` or `xml.dom.minidom.Text`. Since the document is treated as a "flat" stream of events, the document "tree" is implicitly traversed and the desired elements are found regardless of their depth in the tree. In other words, one does not need to consider hierarchical issues such as recursive searching of the document nodes, although if the context of elements were important, one would either need to maintain some context-related state (i.e. remembering where one is in the document at any given point) or to make use of the [`DOMEventStream.expandNode()`](#xml.dom.pulldom.DOMEventStream.expandNode "xml.dom.pulldom.DOMEventStream.expandNode") method and switch to DOM-related processing. *class* `xml.dom.pulldom.``PullDom`(*documentFactory=None*)Subclass of [`xml.sax.handler.ContentHandler`](xml.sax.handler.xhtml#xml.sax.handler.ContentHandler "xml.sax.handler.ContentHandler"). *class* `xml.dom.pulldom.``SAX2DOM`(*documentFactory=None*)Subclass of [`xml.sax.handler.ContentHandler`](xml.sax.handler.xhtml#xml.sax.handler.ContentHandler "xml.sax.handler.ContentHandler"). `xml.dom.pulldom.``parse`(*stream\_or\_string*, *parser=None*, *bufsize=None*)Return a [`DOMEventStream`](#xml.dom.pulldom.DOMEventStream "xml.dom.pulldom.DOMEventStream") from the given input. *stream\_or\_string* may be either a file name, or a file-like object. *parser*, if given, must be an [`XMLReader`](xml.sax.reader.xhtml#xml.sax.xmlreader.XMLReader "xml.sax.xmlreader.XMLReader") object. This function will change the document handler of the parser and activate namespace support; other parser configuration (like setting an entity resolver) must have been done in advance. If you have XML in a string, you can use the [`parseString()`](#xml.dom.pulldom.parseString "xml.dom.pulldom.parseString") function instead: `xml.dom.pulldom.``parseString`(*string*, *parser=None*)Return a [`DOMEventStream`](#xml.dom.pulldom.DOMEventStream "xml.dom.pulldom.DOMEventStream") that represents the (Unicode) *string*. `xml.dom.pulldom.``default_bufsize`Default value for the *bufsize* parameter to [`parse()`](#xml.dom.pulldom.parse "xml.dom.pulldom.parse"). The value of this variable can be changed before calling [`parse()`](#xml.dom.pulldom.parse "xml.dom.pulldom.parse") and the new value will take effect. ## DOMEventStream Objects *class* `xml.dom.pulldom.``DOMEventStream`(*stream*, *parser*, *bufsize*)`getEvent`()Return a tuple containing *event* and the current *node* as `xml.dom.minidom.Document` if event equals `START_DOCUMENT`, `xml.dom.minidom.Element` if event equals `START_ELEMENT` or `END_ELEMENT` or `xml.dom.minidom.Text` if event equals `CHARACTERS`. The current node does not contain information about its children, unless [`expandNode()`](#xml.dom.pulldom.DOMEventStream.expandNode "xml.dom.pulldom.DOMEventStream.expandNode") is called. `expandNode`(*node*)Expands all children of *node* into *node*. Example: ``` from xml.dom import pulldom xml = '<html><title>Foo</title> <p>Some text <div>and more</div></p> </html>' doc = pulldom.parseString(xml) for event, node in doc: if event == pulldom.START_ELEMENT and node.tagName == 'p': # Following statement only prints '<p/>' print(node.toxml()) doc.expandNode(node) # Following statement prints node with all its children '<p>Some text <div>and more</div></p>' print(node.toxml()) ``` `reset`() ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](xml.sax.xhtml "xml.sax --- Support for SAX2 parsers") | - [上一頁](xml.dom.minidom.xhtml "xml.dom.minidom --- Minimal DOM implementation") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [結構化標記處理工具](markup.xhtml) ? - $('.inline-search').show(0); | ? [版權所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 軟件基金會是一個非盈利組織。 [請捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [發現了問題](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 創建。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看