Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
python3.8.1
/
Doc
/
library
/
xml.dom.pulldom.rst
python3.8.1
/
Doc
/
library
/
xml.dom.pulldom.rst
xml.dom.pulldom.rst 5.16 KB
Copy Edit Raw Blame History
zhangweibo authored 2021年11月16日 09:46 +08:00 . git init

:mod:`xml.dom.pulldom` --- Support for building partial DOM trees

.. module:: xml.dom.pulldom
 :synopsis: Support for building partial DOM trees from SAX events.

.. moduleauthor:: Paul Prescod <paul@prescod.net>

Source code: :source:`Lib/xml/dom/pulldom.py`


The :mod:`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 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.

Warning

The :mod:`xml.dom.pulldom` module is not secure against maliciously constructed data. If you need to parse untrusted or unauthenticated data see :ref:`xml-vulnerabilities`.

.. versionchanged:: 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)


Example:

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:

node is an object of type :class:`xml.dom.minidom.Document`, :class:`xml.dom.minidom.Element` or :class:`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 :func:`DOMEventStream.expandNode` method and switch to DOM-related processing.

Subclass of :class:`xml.sax.handler.ContentHandler`.

Subclass of :class:`xml.sax.handler.ContentHandler`.

.. function:: parse(stream_or_string, parser=None, bufsize=None)

 Return a :class:`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
 :class:`~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 :func:`parseString` function instead:

.. function:: parseString(string, parser=None)

 Return a :class:`DOMEventStream` that represents the (Unicode) *string*.

.. data:: default_bufsize

 Default value for the *bufsize* parameter to :func:`parse`.

 The value of this variable can be changed before calling :func:`parse` and
 the new value will take effect.

DOMEventStream Objects

.. deprecated:: 3.8
 Support for :meth:`sequence protocol <__getitem__>` is deprecated.

.. method:: getEvent()

 Return a tuple containing *event* and the current *node* as
 :class:`xml.dom.minidom.Document` if event equals :data:`START_DOCUMENT`,
 :class:`xml.dom.minidom.Element` if event equals :data:`START_ELEMENT` or
 :data:`END_ELEMENT` or :class:`xml.dom.minidom.Text` if event equals
 :data:`CHARACTERS`.
 The current node does not contain information about its children, unless
 :func:`expandNode` is called.

.. method:: 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())

.. method:: DOMEventStream.reset()
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.8.1.git
git@gitee.com:python_sourcecode/python3.8.1.git
python_sourcecode
python3.8.1
python3.8.1
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /