xml.dom.pulldom
— 支持构建部分 DOM (文档对象模型) 树
¶
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 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 is not secure against maliciously constructed data. If you need to parse untrusted or unauthenticated data see
XML vulnerabilities
.
Changed in version 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)