Friday, April 15, 2011

Creating an XML document in Python



root = xml.Element('bestsellers')
root.attrib['yyyymm'] = "201012"
root.attrib['topN'] = str(1000)
idx = 0
for i in top1000_list:
idx += 1
child = xml.Element('item')
root.append(child)
child.attrib['rank'] = str(idx)
for k,v in i.items():
child.attrib['isbn'] = k
child.attrib['count'] = v
print xml.tostring(root)



Result is...


































No comments: