python:是否有XML解析器实现为生成器? [英] python: is there an XML parser implemented as a generator?
问题描述
我想动态"解析一个大的XML文件.我想使用python生成器执行此操作.我已经尝试过"xml.etree.cElementTree"的"iterparse"(这真的很好),但仍然没有生成器.
I'd like to parse a big XML file "on the fly". I'd like to use a python generator to perform this. I've tried "iterparse" of "xml.etree.cElementTree" (which is really nice) but still not a generator.
其他建议?
推荐答案
实时"解析和文档树并不真正兼容.通常使用SAX样式的解析器(例如,Python的标准 xml.sax ).基本上,您必须定义一个带有用于处理各种事件(例如startElement,endElement等)的处理程序的类,然后解析器将在解析XML文件时调用这些方法.
"On the fly" parsing and document trees are not really compatible. SAX-style parsers are usually used for that (for example, Python's standard xml.sax). You basically have to define a class with handlers for various events like startElement, endElement, etc. and the parser will call the methods as it parses the XML file.
这篇关于python:是否有XML解析器实现为生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!