elementTree无法分析unicode xm

2024-10-01 07:42:17 发布

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

我有以下xml:

<Earth>
 <country name="Česká republika" population="8900000">
    <capital>Praha1</capital>        
  </country>
</Earth>

但当我试图解析它时,却出现了错误:

^{pr2}$

我的代码:

 tree=etree.parse(input) # input -> file.xml

Tags: 代码nametreeinput错误xmlcountryetree
1条回答
网友
1楼 · 发布于 2024-10-01 07:42:17

正如arhimmel指出的,这个问题很可能是编码问题。etree.parse允许传递类似文件的对象和路径,因此您可以尝试在代码顶部添加import codecs,然后将input替换为codecs.open("file.xml", encoding="UTF-8")。在

相关问题 更多 >