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