我有一個XML文件,它看起來像這樣:Python的XML解析問題
<!DOCTYPE ROOT SYSTEM "zombie.dtd">
<ROOT>
<row>
<field name="buildid">26960</field>
<field name="cast(status as char)">Filesystem 1K-blocks Used Available Use% Mounted on
C:cygwinin 285217976 88055920 197162056 31% /usr/bin
C:cygwinlib 285217976 88055920 197162056 31% /usr/lib
C:cygwin 285217976 88055920 197162056 31%/
c: 285217976 88055920 197162056 31% /cygdrive/c
d: 285217976 88055920 197162056 31% /cygdrive/d</field>
<field name="eventtime">2011-05-25 16:26:09</field>
<field name="schedulerid">13</field>
</row>
,我試圖分析出各個字段(buildid,狀態,EVENTTIME等),但我由於我所有的函數調用沒有得到,這裏是我在做什麼:
log("Parsing XML file...")
try:
xml = ET.parse(xml_file)
except Exception, inst:
print "Unexpected error opening %s: %s" % (file, inst)
sys.exit(1)
log("Parsing Complete")
#store the root of the element tree
root = xml.getroot()
zombies = []
for zombie in root.findall('row/'):
#read the zombie data
buildID = zombie.get('buildid')
print buildID
status = zombie.get('cast(status as char')
print status
eventTime = zombie.get('eventtime')
print eventTime
schedulerID = zombie.get('schedulerid')
print schedulerID
#create a zombie object
#z = Zombie(buildID, status, eventTime, schedulerID)
#zombies.append(z)
有人可以告訴我我做錯了什麼嗎?
感謝
好了,所以我怎麼領域標籤內的價值?我是否需要爲所需的所有數據測試字段標記的名稱屬性? – 2011-06-13 17:16:12
非常感謝史蒂夫 – 2011-06-13 18:34:05