【发布时间】:2012-04-25 22:46:27
【问题描述】:
我有以下 xml:
<Earth>
<country name="Česká republika" population="8900000">
<capital>Praha1</capital>
</country>
</Earth>
但是当我尝试解析它失败并出现错误:
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 2, column 20
我的代码:
tree=etree.parse(input) # input -> file.xml
【问题讨论】:
-
XML文件的编码是什么?您需要确保解码为 Unicode。
-
非常类似于stackoverflow.com/questions/147741/…尝试用正确的编码打开
-
是的,但我没有以任何方式打开它,我只是使用文件名作为 ET.parse 的参数,这就是我无法手动设置编码的原因(或者我是不知道ET方法,可以这样做)
标签: python xml xml-parsing elementtree