0
我正在使用python 3.5如何将xml.etree.ElementTree中的XML内容写入文件?
为了从word文档中提取文本内容,我使用了xml.etree.ElementTree。 我无法将生成的XML内容写入其他文件。
下面是我的一段代码
import zipfile
import xml.etree.ElementTree
with zipfile.ZipFile('<path to docx file>') as docx:
tree = xml.etree.ElementTree.XML(docx.read('word/document.xml'))
我已经尝试了两种方法: tree.write('<path to file>', encoding='utf8')
和
xml.etree.ElementTree.write('<path to file>')
但是这两种方法都引发错误为:
AttributeError的: 'xml.etree.ElementTree.Element'对象没有属性'写'
请帮助。
它的工作原理。谢谢。 – Bonson