我有以下必须使用 python 的 minidom 解析的 XML 文档:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bash-function activated="True">
<name>lsal</name>
<description>List directory content (-al)</description>
<code>ls -al</code>
</bash-function>
<bash-function activated="True">
<name>lsl</name>
<description>List directory content (-l)</description>
<code>ls -l</code>
</bash-function>
</root>
这是我试图解析的代码(基本部分):
from modules import BashFunction
from xml.dom.minidom import parse
class FuncDoc(object):
def __init__(self, xml_file):
self.active_func = []
self.inactive_func = []
try:
self.dom = parse(xml_file)
except Exception as inst:
print type(inst)
print inst.args
print inst
不幸的是,我遇到了一些错误。这是堆栈跟踪:
<class 'xml.parsers.expat.ExpatError'>
('no element found: line 1, column 0',)
no element found: line 1, column 0
作为一个python初学者,能否请您指出问题的根源。