GCh*_*orn 3 python wordpress xml-parsing
我正在尝试使用Python的xml.etree.ElementTree.parse()函数来解析我通过从WordPress博客导出所有内容而创建的XML文件.但是,当我这样做时:
import xml.etree.ElementTree as xml
tree = xml.parse('/path/to/file.xml')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
这是我的XML文件的第189行:
<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blogname.wordpress.com/osd.xml" title="blog name" />
Run Code Online (Sandbox Code Playgroud)
我已经看到很多关于这个错误的问题出现在Android开发中,但我不知道是否以及如何适用于我的情况.有人能帮忙吗?
向所有人道歉,这显然是愚蠢的,但事实证明我在文档中根本没有"atom"的命名空间定义.我猜测"未绑定的前缀"意味着前缀"atom"没有"绑定"到命名空间定义?
无论如何,添加所述定义已经解决了这个问题.虽然它让我想知道为什么WordPress导出XML文件没有对他们使用的所有命名空间的正确定义...
| 归档时间: |
|
| 查看次数: |
2756 次 |
| 最近记录: |