# toXml.py - Imports humod06.txt to XML.
import csv
from xml.dom.minidom import parseString
doc = parseString('<skill_descriptors lvl="0"/>')
reader = csv.reader(open('humod06.txt', 'rb'), delimiter='\t')
rownum = 0
elm = doc.documentElement
for row in reader:
if rownum == 0:
header = row
else:
sd = doc.createElement('skill_descriptor')
colnum = 0
for col in row:
#print '%-8s: %s' % (header[colnum], col)
sd.setAttribute(header[colnum].lower(), unicode(col.strip(), 'utf8'))
colnum += 1
while row[3] <= elm.getAttribute('lvl'):
elm = elm.parentNode
elm.appendChild(sd)
elm = sd
rownum += 1
print(doc.toxml())
print('rows: %s' % rownum)
doc.unlink()
Export this post to PDF document