hytos / DTI_PID / DTI_PID / XmlGenerator.py @ 92f30bc0
이력 | 보기 | 이력해설 | 다운로드 (16.9 KB)
1 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse |
---|---|
2 |
import symbol |
3 |
import SymbolBase |
4 |
import TextInfo as ti |
5 |
import math |
6 |
import os |
7 |
import sys |
8 |
from AppDocData import AppDocData |
9 | |
10 |
ROOT_NODE_NAME = "DWG"
|
11 |
ROOT_DWGNAME_NODE_NAME = "DWGNAME"
|
12 |
ROOT_SIZE_NODE_NAME = "SIZE"
|
13 | |
14 |
SYMBOL_LIST_NODE_NAME = "SYMBOLS"
|
15 |
TEXT_INFO_LIST_NODE_NAME = "TEXTINFOS"
|
16 |
IMG_LINE_LIST_NODE_NAME = "IMGLINES"
|
17 |
NOTE_TEXT_INFO_LIST_NOTE_NAME = "NOTES"
|
18 | |
19 |
SCATEGORY_NODE_NAME = "SYMBOL"
|
20 | |
21 |
SNAME_NODE_NAME = "NAME"
|
22 | |
23 |
STYPE_NOTE_NAME = "TYPE"
|
24 | |
25 |
SCLASS_NODE_NAME = "CLASS"
|
26 | |
27 |
SITEM_NODE_NAME = "ITEM"
|
28 | |
29 |
SSUB_TEXT = "TEXT"
|
30 |
SSUB_ORIGINAL_POINT = "ORIGINALPOINT"
|
31 |
SSUB_CONNECTION_POINT = "CONNECTIONPOINT"
|
32 |
SSUB_PARENT = "PARENT"
|
33 |
SSUB_CHILD = "CHILD"
|
34 |
SSUB_ANGLE = "ANGLE"
|
35 |
SSUB_START_POINT = "STARTPOINT"
|
36 |
SSUB_SIZE = "SIZE"
|
37 | |
38 |
LINE_NO_LIST_NODE_NAME = "LINE_NOS"
|
39 | |
40 |
TEXT_INFO_NODE_NAME = "TEXTINFO"
|
41 |
TTEXT_NODE_NAME = "TEXT"
|
42 |
TTEXT_X_NODE_NAME = "X"
|
43 |
TTEXT_Y_NODE_NAME = "Y"
|
44 |
TTEXT_WIDTH_NODE_NAME = "WIDTH"
|
45 |
TTEXT_HEIGHT_NODE_NAME = "HEIGHT"
|
46 |
TTEXT_ANGLE_NODE_NAME = "ANGLE"
|
47 | |
48 | |
49 |
IMG_LINE_NODE_NAME = "IMGLINE"
|
50 |
ISP_NODE_NAME = "START"
|
51 |
IEP_NODE_NAME = "END"
|
52 | |
53 |
NOTE_TEXT_INFO_NOTE_NAME = "NOTE"
|
54 |
TNOTE_TEXT_NODE_NAME = "TEXT"
|
55 |
TNOTE_TEXT_X_NODE_NAME = "X"
|
56 |
TNOTE_TEXT_Y_NODE_NAME = "Y"
|
57 |
TNOTE_TEXT_WIDTH_NODE_NAME = "WIDTH"
|
58 |
TNOTE_TEXT_HEIGHT_NODE_NAME = "HEIGHT"
|
59 |
TNOTE_TEXT_ANGLE_NODE_NAME = "ANGLE"
|
60 | |
61 |
LINE_INFOS_NODE_NAME = "LINEINFOS"
|
62 |
LLINE_INFO_NODE_NAME = "LINEINFO"
|
63 |
LLINE_UUID = "UUID"
|
64 |
LLINE_START_POINT_NODE_NAME = "STARTPOINT"
|
65 |
LLINE_END_POINT_NODE_NAME = "ENDPOINT"
|
66 | |
67 |
LINE_NOS_NODE_NAME = "LINENOS"
|
68 |
TRIM_LINE_NOS_NODE_NAME = "TRIMLINENOS"
|
69 | |
70 |
UNKNOWNS_NODE_NAME = "UNKNOWNS"
|
71 | |
72 |
'''
|
73 |
@brief
|
74 |
@author
|
75 |
@date
|
76 |
@history 2018.05.25 Jeongwoo Remove parameter 'imgLineList'
|
77 |
'''
|
78 |
def writeXml(pidName, pidWidth, pidHeight, searchedSymbolList, textInfoList, noteTextInfoList): |
79 |
path = os.path.join(AppDocData.instance().getCurrentProject().getTempPath(), pidName + '.xml')
|
80 |
try:
|
81 |
xmlData = generateXml(pidName, pidWidth, pidHeight, searchedSymbolList, textInfoList, noteTextInfoList) |
82 |
ElementTree(xmlData).write(path) |
83 |
except Exception as ex: |
84 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
85 | |
86 |
return path
|
87 | |
88 |
'''
|
89 |
@brief write output xml
|
90 |
@author humkyung
|
91 |
@date 2018.04.23
|
92 |
'''
|
93 |
def writeOutputXml(pidName, pidWidth, pidHeight): |
94 |
try:
|
95 |
path = os.path.join(AppDocData.instance().getCurrentProject().getOutputPath(), pidName + '.xml')
|
96 | |
97 |
xmlData = generateOutputXml(pidName, pidWidth, pidHeight) |
98 |
ElementTree(xmlData).write(path) |
99 |
except Exception as ex: |
100 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
101 | |
102 |
return path
|
103 | |
104 |
'''
|
105 |
@brief generate output xml for converter
|
106 |
@author humkyung
|
107 |
@date 2018.04.23
|
108 |
@history humkyung 2018.05.02 write equipment node
|
109 |
humkyung 2018.05.10 write orphan lines
|
110 |
humkyung 2018.05.16 remove code to write orphan lines and symbols
|
111 |
humkyung 2018.09.06 write text to xml
|
112 |
'''
|
113 |
def generateOutputXml(pidName, pidWidth, pidHeight): |
114 |
appDocData = AppDocData.instance() |
115 | |
116 |
try:
|
117 |
xml = Element(ROOT_NODE_NAME) # Root Node
|
118 |
SubElement(xml, ROOT_DWGNAME_NODE_NAME).text = pidName |
119 |
SubElement(xml, ROOT_SIZE_NODE_NAME).text = str(pidWidth) + "," + str(pidHeight) |
120 |
SubElement(xml, 'UNIT').text = appDocData.getCurrentProject().unit()
|
121 | |
122 |
for equipment in appDocData.equipments: |
123 |
equipmentNode = Element('EQUIPMENT')
|
124 |
equipmentNode.append(equipment.toXml()) |
125 |
xml.append(equipmentNode) |
126 | |
127 |
sortedList = sorted(appDocData.lineNos, key=lambda param:param.text()) |
128 |
for lineno in sortedList: |
129 |
xml.append(lineno.toXml()) |
130 | |
131 |
for text in appDocData.texts: |
132 |
xml.append(text.toXml()) |
133 |
except Exception as ex: |
134 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
135 | |
136 |
return xml
|
137 | |
138 |
'''
|
139 |
@history 2018.04.30 Jeongwoo noteTextInfoList None Check
|
140 |
2018.05.25 Jeongwoo Remove parameter 'imgLineList' and Check if variable is None or not
|
141 |
'''
|
142 |
def generateXml(pidName, pidWidth, pidHeight, searchedSymbolList, textInfoList, noteTextInfoList): |
143 |
xml = Element(ROOT_NODE_NAME) # Root Node
|
144 |
SubElement(xml, ROOT_DWGNAME_NODE_NAME).text = pidName |
145 |
SubElement(xml, ROOT_SIZE_NODE_NAME).text = str(pidWidth) + "," + str(pidHeight) |
146 |
try:
|
147 |
if searchedSymbolList is not None: |
148 |
symbolListNode = Element(SYMBOL_LIST_NODE_NAME) # Symbol List Node
|
149 |
sortedList = sorted(searchedSymbolList, key=lambda sym:sym.getName()) |
150 |
for symbol in sortedList: |
151 |
node = getSymbolInfoNode(symbol) |
152 |
symbolListNode.append(node) |
153 | |
154 |
xml.append(symbolListNode) |
155 | |
156 |
if textInfoList is not None: |
157 |
textInfoListNode = Element(TEXT_INFO_LIST_NODE_NAME) # Text Info List Node
|
158 |
for textInfo in textInfoList: |
159 |
node = getTextInfoNode(textInfo) |
160 |
textInfoListNode.append(node) |
161 | |
162 |
xml.append(textInfoListNode) |
163 | |
164 |
noteTextInfoListNode = Element(NOTE_TEXT_INFO_LIST_NOTE_NAME) |
165 |
if noteTextInfoList is not None: |
166 |
for noteTextInfo in noteTextInfoList: |
167 |
node = getNoteTextInfoNode(noteTextInfo) |
168 |
noteTextInfoListNode.append(node) |
169 | |
170 |
xml.append(noteTextInfoListNode) |
171 |
except Exception as ex: |
172 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
173 | |
174 |
return xml
|
175 | |
176 |
def getSymbolInfoNode(symbol): |
177 |
sName = symbol.getName() |
178 |
sSp = symbol.getSp() |
179 |
sAngle = symbol.getRotatedAngle() |
180 |
sType = symbol.getType() |
181 |
sText = symbol.getText() |
182 |
sOriginalPoint = symbol.getOriginalPoint() |
183 |
sConnectionPoint = symbol.getConnectionPoint() |
184 |
sWidth = symbol.getWidth() |
185 |
sHeight = symbol.getHeight() |
186 |
sBaseSymbol = symbol.getBaseSymbol() |
187 |
sAdditionalSymbol = symbol.getAdditionalSymbol() |
188 | |
189 |
sCategoryNode = Element(SCATEGORY_NODE_NAME) |
190 | |
191 |
sNameNode = Element(SNAME_NODE_NAME) |
192 |
sNameNode.text = sName |
193 | |
194 |
sTypeNode = Element(STYPE_NOTE_NAME) |
195 |
sTypeNode.text = sType |
196 |
|
197 |
sOriginalPointNode = Element(SSUB_ORIGINAL_POINT) |
198 |
sOpX = sSp[0] + int(sOriginalPoint.split(',')[0]) |
199 |
sOpY = sSp[1] + int(sOriginalPoint.split(',')[1]) |
200 |
sOriginalPointNode.text = str(sOpX) + "," + str(sOpY) |
201 | |
202 |
sConnectionPointNode = Element(SSUB_CONNECTION_POINT) |
203 |
convertedConnectionPoint = ""
|
204 |
if sConnectionPoint:
|
205 |
splitConnectionPoint = sConnectionPoint.split("/")
|
206 |
for index in range(len(splitConnectionPoint)): |
207 |
if index != 0: |
208 |
convertedConnectionPoint = convertedConnectionPoint + "/"
|
209 |
item = splitConnectionPoint[index] |
210 |
sCpX = sSp[0] + int(item.split(',')[0]) |
211 |
sCpY = sSp[1] + int(item.split(',')[1]) |
212 |
tempStr = str(sCpX) + "," + str(sCpY) |
213 |
convertedConnectionPoint = convertedConnectionPoint + tempStr |
214 |
sConnectionPointNode.text = convertedConnectionPoint |
215 | |
216 |
sBaseSymbolNode = Element(SSUB_PARENT) |
217 |
sBaseSymbolNode.text = sBaseSymbol |
218 | |
219 |
if sAdditionalSymbol is not None: |
220 |
sAdditionalSymbolNode = Element(SSUB_CHILD) |
221 |
sAdditionalSymbolNode.text = sAdditionalSymbol |
222 |
sCategoryNode.append(sAdditionalSymbolNode) |
223 | |
224 |
sAngleNode = Element(SSUB_ANGLE) |
225 |
sAngleNode.text = str(round(math.radians(sAngle), 2)) |
226 | |
227 |
sTextNode = Element(SSUB_TEXT) |
228 |
sTextNode.text = sText |
229 | |
230 |
sStartPointNode = Element(SSUB_START_POINT) |
231 |
sStartPointNode.text = str(sSp[0]) + "," + str(sSp[1]) |
232 | |
233 |
sSizeNode = Element(SSUB_SIZE) |
234 |
sSizeNode.text = str(sWidth) + "," + str(sHeight) |
235 | |
236 |
sCategoryNode.append(sNameNode) |
237 |
sCategoryNode.append(sTypeNode) |
238 |
sCategoryNode.append(sOriginalPointNode) |
239 |
sCategoryNode.append(sConnectionPointNode) |
240 |
sCategoryNode.append(sBaseSymbolNode) |
241 |
sCategoryNode.append(sAngleNode) |
242 |
sCategoryNode.append(sTextNode) |
243 |
sCategoryNode.append(sStartPointNode) |
244 |
sCategoryNode.append(sSizeNode) |
245 | |
246 |
return sCategoryNode
|
247 | |
248 |
def getTextInfoNode(textInfo): |
249 |
text = textInfo.getText() |
250 |
x = textInfo.getX() |
251 |
y = textInfo.getY() |
252 |
w = textInfo.getW() |
253 |
h = textInfo.getH() |
254 |
angle = textInfo.getAngle() |
255 | |
256 |
tInfoNode = Element(TEXT_INFO_NODE_NAME) |
257 | |
258 |
textNode = Element(TTEXT_NODE_NAME) |
259 |
textNode.text = text |
260 | |
261 |
xNode = Element(TTEXT_X_NODE_NAME) |
262 |
xNode.text = str(x)
|
263 | |
264 |
yNode = Element(TTEXT_Y_NODE_NAME) |
265 |
yNode.text = str(y)
|
266 | |
267 |
widthNode = Element(TTEXT_WIDTH_NODE_NAME) |
268 |
widthNode.text = str(w)
|
269 | |
270 |
heightNode = Element(TTEXT_HEIGHT_NODE_NAME) |
271 |
heightNode.text = str(h)
|
272 | |
273 |
angleNode = Element(TTEXT_ANGLE_NODE_NAME) |
274 |
angleNode.text = str(round(math.radians(angle), 2)) |
275 |
|
276 |
tInfoNode.append(textNode) |
277 |
tInfoNode.append(xNode) |
278 |
tInfoNode.append(yNode) |
279 |
tInfoNode.append(widthNode) |
280 |
tInfoNode.append(heightNode) |
281 |
tInfoNode.append(angleNode) |
282 | |
283 |
return tInfoNode
|
284 | |
285 |
def getNoteTextInfoNode(noteTextInfo): |
286 |
text = noteTextInfo.getText() |
287 |
x = noteTextInfo.getX() |
288 |
y = noteTextInfo.getY() |
289 |
w = noteTextInfo.getW() |
290 |
h = noteTextInfo.getH() |
291 |
angle = noteTextInfo.getAngle() |
292 | |
293 |
ntInfoNode = Element(NOTE_TEXT_INFO_NOTE_NAME) |
294 | |
295 |
textNode = Element(TNOTE_TEXT_NODE_NAME) |
296 |
textNode.text = text |
297 | |
298 |
xNode = Element(TNOTE_TEXT_X_NODE_NAME) |
299 |
xNode.text = str(x)
|
300 | |
301 |
yNode = Element(TNOTE_TEXT_Y_NODE_NAME) |
302 |
yNode.text = str(y)
|
303 | |
304 |
widthNode = Element(TNOTE_TEXT_WIDTH_NODE_NAME) |
305 |
widthNode.text = str(w)
|
306 | |
307 |
heightNode = Element(TNOTE_TEXT_HEIGHT_NODE_NAME) |
308 |
heightNode.text = str(h)
|
309 | |
310 |
angleNode = Element(TNOTE_TEXT_ANGLE_NODE_NAME) |
311 |
angleNode.text = str(round(math.radians(angle), 2)) |
312 |
|
313 |
ntInfoNode.append(textNode) |
314 |
ntInfoNode.append(xNode) |
315 |
ntInfoNode.append(yNode) |
316 |
ntInfoNode.append(widthNode) |
317 |
ntInfoNode.append(heightNode) |
318 |
ntInfoNode.append(angleNode) |
319 | |
320 |
return ntInfoNode
|
321 | |
322 |
'''
|
323 |
@brief Append LineInfo Data
|
324 |
@author Jeongwoo
|
325 |
@date 2018.05.28
|
326 |
'''
|
327 |
def appendLineInfo(xmlPath, lineInfo): |
328 |
tree = parse(xmlPath) |
329 |
root = tree.getroot() |
330 |
lineInfosNode = root.find(LINE_INFOS_NODE_NAME) |
331 |
if lineInfosNode is not None: |
332 |
lineInfosNode.clear() |
333 |
else:
|
334 |
lineInfosNode = Element(LINE_INFOS_NODE_NAME) |
335 |
root.append(lineInfosNode) |
336 |
for line in lineInfo: |
337 |
lineInfoNode = Element(LLINE_INFO_NODE_NAME) |
338 |
#uuidNode = Element(LLINE_UUID)
|
339 |
#uuidNode.text = line.uid
|
340 |
startPointNode = Element(LLINE_START_POINT_NODE_NAME) |
341 |
startPointNode.text = str(line.startPoint()[0])+","+str(line.startPoint()[1]) |
342 |
endPointNode = Element(LLINE_END_POINT_NODE_NAME) |
343 |
endPointNode.text = str(line.endPoint()[0])+","+str(line.endPoint()[1]) |
344 |
#lineInfoNode.append(uuidNode)
|
345 |
lineInfoNode.append(startPointNode) |
346 |
lineInfoNode.append(endPointNode) |
347 |
lineInfosNode.append(lineInfoNode) |
348 |
|
349 | |
350 |
ElementTree(root).write(xmlPath) |
351 |
|
352 |
'''
|
353 |
@brief Write xml data by scene
|
354 |
@author Jeongwoo
|
355 |
@date 2018.05.30
|
356 |
@history 2018.05.30 Jeongwoo Create node by item object
|
357 |
2018.06.12 Jeongwoo Add if-statement for QEngineeringLineNoTextItem data node
|
358 |
2018.06.14 Jeongwoo Add if-statement for QEngineeringUnknownItem data node
|
359 |
2018.11.26 euisung remove scene dependency
|
360 |
'''
|
361 |
def writeXmlOnScene(pidName, pidWidth, pidHeight): |
362 |
from EngineeringNoteItem import QEngineeringNoteItem |
363 |
from EngineeringTextItem import QEngineeringTextItem |
364 |
from EngineeringLineItem import QEngineeringLineItem |
365 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
366 |
from EngineeringUnknownItem import QEngineeringUnknownItem |
367 |
from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem |
368 |
from QEngineeringSizeTextItem import QEngineeringSizeTextItem |
369 |
from SymbolSvgItem import SymbolSvgItem |
370 | |
371 |
appDocData = AppDocData.instance() |
372 |
items = [] |
373 |
items = appDocData.allItems |
374 |
path = os.path.join(AppDocData.instance().getCurrentProject().getTempPath(), pidName + '.xml')
|
375 | |
376 |
xml = Element(ROOT_NODE_NAME) # Root Node
|
377 |
SubElement(xml, ROOT_DWGNAME_NODE_NAME).text = pidName |
378 |
SubElement(xml, ROOT_SIZE_NODE_NAME).text = str(pidWidth) + "," + str(pidHeight) |
379 |
symbolListNode = Element(SYMBOL_LIST_NODE_NAME) # Symbol List Node
|
380 |
textInfoListNode = Element(TEXT_INFO_LIST_NODE_NAME) # Text Info List Node
|
381 |
noteTextInfoListNode = Element(NOTE_TEXT_INFO_LIST_NOTE_NAME) |
382 |
lineListNode = Element(LINE_INFOS_NODE_NAME) |
383 |
lineNoListNode = Element(LINE_NOS_NODE_NAME) |
384 |
unknownListNode = Element(UNKNOWNS_NODE_NAME) |
385 | |
386 |
# trim line 추가
|
387 |
trimLineNoListNode = Element(TRIM_LINE_NOS_NODE_NAME) |
388 |
|
389 |
try:
|
390 |
resultDic = {} |
391 |
resultDic["Symbol Item"] = [0, []] |
392 |
resultDic["Line Item"] = [0, []] |
393 |
resultDic["Line No Text Item"] = [0, []] |
394 |
resultDic["Text Item"] = [0, []] |
395 |
resultDic["Note Item"] = [0, []] |
396 |
resultDic["Unknown Item"] = [0, []] |
397 |
resultDic["Trim Line Item"] = [0, []] |
398 |
resultDic["Size Item"] = [0, []] |
399 |
|
400 | |
401 |
for item in items: |
402 |
if issubclass(type(item), SymbolSvgItem): |
403 |
symbolNode = item.toXml() |
404 |
if symbolNode is None: continue |
405 |
if type(symbolNode) is str: |
406 |
resultDic["Symbol Item"][1].append(symbolNode) |
407 |
else:
|
408 |
resultDic["Symbol Item"][0] += 1 |
409 |
symbolListNode.append(symbolNode) |
410 |
elif type(item) is QEngineeringLineItem: |
411 |
lineNode = item.toXml() |
412 |
if type(lineNode) is str: |
413 |
resultDic["Line Item"][1].append(lineNode) |
414 |
else:
|
415 |
resultDic["Line Item"][0] += 1 |
416 |
lineListNode.append(lineNode) |
417 |
elif type(item) is QEngineeringLineNoTextItem: |
418 |
lineNoNode = item.toXml() |
419 |
if type(lineNoNode) is str: |
420 |
resultDic["Line No Text Item"][1].append(lineNoNode) |
421 |
else:
|
422 |
resultDic["Line No Text Item"][0] += 1 |
423 |
lineNoListNode.append(lineNoNode) |
424 |
elif type(item) is QEngineeringTextItem: |
425 |
textNode = item.toXml() |
426 |
if type(textNode) is str: |
427 |
resultDic["Text Item"][1].append(textNode) |
428 |
else:
|
429 |
resultDic["Text Item"][0] += 1 |
430 |
textInfoListNode.append(textNode) |
431 |
elif type(item) is QEngineeringNoteItem: |
432 |
noteNode = item.toXml(name = 'NOTE')
|
433 |
if type(noteNode) is str: |
434 |
resultDic["Note Item"][1].append(noteNode) |
435 |
else:
|
436 |
resultDic["Note Item"][0] += 1 |
437 |
noteTextInfoListNode.append(noteNode) |
438 |
elif type(item) is QEngineeringUnknownItem: |
439 |
unknownNode = item.toXml() |
440 |
if type(unknownNode) is str: |
441 |
resultDic["Unknown Item"][1].append(unknownNode) |
442 |
else:
|
443 |
resultDic["Unknown Item"][0] += 1 |
444 |
unknownListNode.append(unknownNode) |
445 | |
446 |
elif type(item) is QEngineeringSizeTextItem: |
447 |
sizeNode = item.toXml(name='SIZE')
|
448 |
if type(sizeNode) is str: |
449 |
resultDic["Size Item"][1].append(sizeNode) |
450 |
else:
|
451 |
resultDic["Size Item"][0] += 1 |
452 |
textInfoListNode.append(sizeNode) |
453 | |
454 |
for line in appDocData.tracerLineNos: |
455 |
if type(line) is QEngineeringTrimLineNoTextItem: |
456 |
trimNode = line.toXml() |
457 |
if type(trimNode) is str: |
458 |
resultDic["Trim Line Item"][1].append(trimNode) |
459 |
else:
|
460 |
resultDic["Trim Line Item"][0] += 1 |
461 |
trimLineNoListNode.append(trimNode) |
462 | |
463 |
except Exception as ex: |
464 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
465 |
finally:
|
466 |
xml.append(symbolListNode) |
467 |
xml.append(textInfoListNode) |
468 |
xml.append(noteTextInfoListNode) |
469 |
xml.append(lineListNode) |
470 |
xml.append(lineNoListNode) |
471 |
xml.append(unknownListNode) |
472 |
xml.append(trimLineNoListNode) |
473 |
ElementTree(xml).write(path) |
474 | |
475 |
return resultDic
|
476 | |
477 |
def indent(elem, level=0): |
478 |
i = "\n" + level*" " |
479 |
if len(elem): |
480 |
if not elem.text or not elem.text.strip(): |
481 |
elem.text = i + " "
|
482 |
if not elem.tail or not elem.tail.strip(): |
483 |
elem.tail = i |
484 |
for elem in elem: |
485 |
indent(elem, level+1)
|
486 |
if not elem.tail or not elem.tail.strip(): |
487 |
elem.tail = i |
488 |
else:
|
489 |
if level and (not elem.tail or not elem.tail.strip()): |
490 |
elem.tail = i |
491 | |
492 |
return elem
|