3 sample_xml_file = 'sample_rspec.xml'
4 f = open(sample_xml_file, 'r')
8 xml += line.replace('\n', '',).repalce('\t', '').strip()
10 dom = xml.dom.minidom.parseString(xml)
12 def getText(nodelist):
15 if node.nodeType == node.TEXT_NODE:
19 def handleRspec(rspec):
23 # loop through each network element
24 for i in rspec.getElementsByTagName("NetSpec"):
25 # handle networks call
26 tempdic[i] = (handleNetworks(rspec.getElementsByTagName("NetSpec")[i]))
27 # append the temp dict
28 rdict['networks'] = tempdic
31 def handleIfs(interf):
34 # loop through attribs and put key value pair into array
35 for i in interf.attributes:
36 a = node.attributes[i]
37 ifdict[a.name] = a.value
41 def handleNodes(node):
44 # loop through attribs and put key value pair into array
45 for i in node.attributes:
46 a = node.attributes[i]
47 nodict[a.name] = a.value
49 # loop through each IF element
50 for i in node.getElementsByTagName("IfSpec"):
52 tempd[i] = handleIfs(node.getElementByTagName("IfSpec")[i])
57 def handleNetworks(network):
59 ndict = {'name':network.nodeName}
60 # loop through each node element
61 for i in network.getElementsByTagName:
63 tempdict[i] = handleNodes(network.getElementsByTagName("NodeSpec")[i])
65 ndict['nodes'] = tempdict
68 def handleTest(slices):
70 sdict = slice.getElementsByTagName("slices")[0]
71 print "<p>%s</p>" % getText(slice.childNodes)