1 from xml.dom.minidom import *
4 sample_xml_file = 'sample_rspec.xml'
5 f = open(sample_xml_file, 'r')
9 xml += line.replace('\n', '',).replace('\t', '').strip()
11 dom = parseString(xml)
13 def getText(nodelist):
16 if node.nodeType == node.TEXT_NODE:
20 def handleRspec(rspec):
24 # loop through each network element
25 for i in rspec.getElementsByTagName("NetSpec"):
26 # handle networks call
27 temp = handleNetworks(i)
29 # append the temp dict
30 rdict['networks'] = tempdic
33 def handleIfs(interf):
36 # loop through attribs and put key value pair into array
37 for i in interf.attributes:
38 a = node.attributes[i]
39 ifdict[a.name] = a.value
43 def handleNodes(node):
46 # loop through attribs and put key value pair into array
47 for i in node.attributes:
48 a = node.attributes[i]
49 nodict[a.name] = a.value
51 # loop through each IF element
52 for i in node.getElementsByTagName("IfSpec"):
54 tempd.append(handleIfs(i))
59 def handleNetworks(network):
61 ndict = {'name':network.nodeName}
63 # loop through each node element
64 for i in network.getElementsByTagName("NodeSpec"):
66 tempdict.append(handleNodes(i))
68 ndict['nodes'] = tempdict
71 def handleTest(slices):
73 sdict = slice.getElementsByTagName("slices")[0]
74 print "<p>%s</p>" % getText(slice.childNodes)