我有,我有使用Python的minidom命名解析下面的XML文档:与Python的minidom解析文档
<?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
作为一个蟒蛇初学者,请你指点我的问题的根源。
你怎么称呼FuncDoc?这个例子实际上对我很好(至少没有例外) – 2010-09-02 10:03:13
-1因为我没有提供信息 – 2010-09-02 11:13:40
@Ivan van der Wijk,可能是因为我在电脑前24/24。我也没有考虑这方面的重要。我想我调用FuncDom的Constructor非常合乎逻辑。 – 2010-09-02 15:40:34