Python ElementTree解析未绑定前缀错误 [英] Python ElementTree parsing unbound prefix error
本文介绍了Python ElementTree解析未绑定前缀错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用python学习ElementTree。一切似乎都很好,除非我尝试解析带有前缀的xml文件:
I am learning ElementTree in python. Everything seems fine except when I try to parse the xml file with prefix:
test.xml
:
<?xml version="1.0"?>
<abc:data>
<abc:country name="Liechtenstein" rank="1" year="2008">
</abc:country>
<abc:country name="Singapore" rank="4" year="2011">
</abc:country>
<abc:country name="Panama" rank="5" year="2011">
</abc:country>
</abc:data>
当我尝试解析xml时:
When I try to parse the xml:
import xml.etree.ElementTree as ET
tree = ET.parse('test.xml')
我遇到以下错误:
xml.etree.ElementTree.ParseError: unbound prefix: line 2, column 0
我是否需要指定某些内容才能解析a
Do I need to specify something in order to parse a xml file with prefix?
推荐答案
将abc名称空间添加到xml文件中。
Add the abc namespace to your xml file.
<?xml version="1.0"?>
<abc:data xmlns:abc="your namespace">
这篇关于Python ElementTree解析未绑定前缀错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文