-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.py
29 lines (22 loc) · 883 Bytes
/
generator.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
from xml.etree import ElementTree
from xml.dom import minidom
from models import *
class Generator:
@staticmethod
def _prettify(elem):
rough_string = ElementTree.tostring(elem, 'utf-8')
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent=" ")
@staticmethod
def generate_procedure(procedure):
procedureElement = ElementTree.Element('Procedure')
procedureElement.attrib = procedure.generate_properties_dict()
for page in procedure.pages:
pageElement = ElementTree.SubElement(procedureElement, 'Page')
for element in page.elements:
ElementTree.SubElement(
pageElement,
'Element',
element.generate_properties_dict()
)
return Generator._prettify(procedureElement)