forked from bowen1993/BioDesigner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanaXML.py
36 lines (32 loc) · 1.17 KB
/
anaXML.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
35
36
import xml.sax
class PartXMLHandler(xml.sax.ContentHandler):
def __init__(self):
self.currentData = ''
self.isStructure = False
self.row_name = ''
self.type = ''
def startElement(self, tag, attributes):
self.currentData = tag
if tag == 'table_structure':
self.isStructure = True
print '-------Table-------'
print attributes['name']
print '---'
elif tag == 'table_data':
self.isStructure = False
elif tag == 'row':
self.isStructure = False
elif tag == 'field' and self.isStructure:
self.row_name = attributes['Field']
self.type = attributes['Type']
def endElement(self, tag):
if self.currentData == 'table_structure':
self.isStructure = False
elif self.currentData == 'field' and self.isStructure:
print self.row_name + ' Type: ' + self.type
if __name__ == '__main__':
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_namespaces, 0)
handler = PartXMLHandler()
parser.setContentHandler(handler)
parser.parse('new.xml')