-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.py
68 lines (57 loc) · 1.41 KB
/
parser.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import xml.etree.cElementTree as ET
tree = ET.ElementTree(file='test.xml')
root = tree.getroot()
print (root)
print (root.tag,root.attrib)
for c in root:
if c.tag == 'Graphs':
graphNode = c
break
imp = graphNode
#print(graphNode.tag,graphNode.attrib)
def indent(e, level=0):
i = "\n" + level*" "
j = "\n" + (level-1)*" "
if len(e):
if not e.text or not e.text.strip():
e.text = i + " "
if not e.tail or not e.tail.strip():
e.tail = i
for s in e:
indent(s, level+1)
if not e.tail or not e.tail.strip():
e.tail = j
else:
if level and (not e.tail or not e.tail.strip()):
e.tail = j
return e
indent(root)
#ET.dump(root)
#indent(graphNode)
#ET.dump(graphNode)
graphs = []
count = 0
def find_rec(node, element):
def _find_rec(node, element, result):
for el in node.getchildren():
_find_rec(el, element, result)
if node.tag == element:
result.append(node)
res = list()
_find_rec(node, element, res)
return res
def extract(x,graphs):
for c in x:
if(c.tag == "Graph"):
graphs.append(c)
#print (nodes)
return graphs
g_list = extract(imp,graphs)
print(g_list)
atts = []
atts = find_rec(g_list[0],"att")
#print(atts)'atts= g_list[0].iter("att")
atts = atts[:len(atts)-2]
for a in atts:
if (a.attrib['name'] == '_kind'):
print(a.attrib['value'])