解析xml文件并输出到文本fi

2024-05-07 13:11:09 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试解析xml文件(配置.xml)并输出到文本文件。我看了其他类似的问题,但没有一个对我有帮助。使用Python2.7.9

import xml.etree.ElementTree as ET
tree = ET.parse('config.xml')
notags = ET.tostring(tree,encoding='us-ascii',method='text')
print(notags)

输出

^{pr2}$

Tags: 文件importconfigtreeparseasxmlencoding