-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseXML.py
executable file
·34 lines (28 loc) · 1023 Bytes
/
parseXML.py
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
28
29
30
31
32
33
34
#!/usr/bin/python -tt
import xml.etree.ElementTree as ET
import codecs
import sys
import re
def main():
filename = sys.argv[1]
tree = ET.parse(filename)
root = tree.getroot()
datatypes = {}
for d in root.iter('DATATYPE'):
datatypes[d.get('ID')] = d.get('TypeName')
for r in root.iter('REGION'):
print r.get('ID'), r.get('RegionName')
outfile = re.sub(r'\.\w+','',filename) + ".txt"
f = codecs.open(outfile, 'w','utf-8')
for t in root.iter('TABLE'):
f.write('Tablename:' + t.get('Tablename') + '\n')
for col in t.iter("COLUMN"):
if (col.get('PrimaryKey') == '1'):
line = '%15s%10s%40s%30s\n' % (col.get('ColName'), datatypes[col.get('idDatatype')], col.get('Comments'), 'PrimaryKey')
else:
line = '%15s%10s%40s\n' % (col.get('ColName'), datatypes[col.get('idDatatype')], col.get('Comments'))
f.write(line)
f.write('\n')
f.close()
if __name__ == '__main__':
main()