7 # Validate RSPEC hiearchy, values, types, and names using supplied xsd.
9 # Faiyaz Ahmed <faiyaza at cs dot princeton dot edu>
11 # Copyright 2009 Princeton University
12 # http://www.planet-lab.org
16 from xml.dom import minidom
19 def getText(nodelist):
22 if node.nodeType == node.TEXT_NODE:
26 # complexType: a supernode comprised of element nodes below it.
27 def traverseComplexType(cmpTypeNode):
29 if cmpTypeNode.hasChildNodes():
30 for n in cmpTypeNode.getElementsByTagName("xsd:attribute"):
31 _elements[n.getAttribute("name")] = {'type': n.getAttribute("type")}
34 # Element. {name, value, default}
35 def Element(elementDom):
36 node = {} #parsed dict
37 for attr in elementDom.attributes.keys():
38 node[attr] = elementDom.attributes.get(attr).value
41 # Sequence is a list of dicts. Each dict is an element type with Type fields
42 def Sequence(sequenceNode):
45 def buildDict(document):
46 if document.hasChildNodes():
47 for i in document.childNodes: buildDict(i)
48 print document.localName
51 buildDict(minidom.parse(fname))
53 if __name__ == '__main__':
54 main(fname="planetlab.xsd")