我正在尝试使用 Python 的 xml.etree.ElementTree.parse() 函数来解析我通过从 WordPress 博客导出所有内容而创建的 XML 文件。但是,当我这样尝试时:
import xml.etree.ElementTree as xml
tree = xml.parse('/path/to/file.xml')
我收到以下错误:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse
tree.parse(source, parser)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
parser.feed(data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
self._raiseerror(v)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1507, in _raiseerror
raise err
ParseError: unbound prefix: line 189, column 1
这是我的 XML 文件第 189 行的内容:
<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blogname.wordpress.com/osd.xml" title="blog name" />
我已经看到很多关于 Android 开发中出现的这个错误的问题,但我不知道这是否以及如何适用于我的情况。有人能帮忙吗?