forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice18.py
More file actions
27 lines (26 loc) · 833 Bytes
/
practice18.py
File metadata and controls
27 lines (26 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding:utf-8 -*-
from xml.dom import minidom
from xlrd import open_workbook
import re
jdict = {}
axls = open_workbook('city.xls')
sheet1 = axls.sheet_by_name('city')
for i in range(3):
jdict[str(sheet1.cell(i,0).value)] = str(sheet1.cell(i,1).value).decode('gbk')
s = str(jdict)
s = re.sub('{','{\n\t ',s)
s = re.sub('}','\n}',s)
s = re.sub(',',',\n\t',s)
print s
doc = minidom.Document()
root = doc.createElement('root')
doc.appendChild(root)
students = doc.createElement('citys')
comment = doc.createComment(u'\n\t城市信息\n')
students.appendChild(comment)
students_text = doc.createTextNode(s.decode('unicode_escape'))
students.appendChild(students_text)
root.appendChild(students)
f = open("city.xml", "wb")
f.write(doc.toprettyxml(indent = "", newl = "\n", encoding = "utf-8"))
f.close()