diff --git a/src/view/utils.py b/src/view/utils.py index 48592c7..847a31d 100644 --- a/src/view/utils.py +++ b/src/view/utils.py @@ -7,13 +7,39 @@ def clean_label(label): def check_export(model): - exported_string = export_to_xml(model) + exported_string = prettify_xml(export_to_xml(model)) model.import_xml(exported_string) - exported_string_2 = export_to_xml(model) + exported_string_2 = prettify_xml(export_to_xml(model)) - if exported_string == exported_string_2: - window.console.log("OK") - else: - window.console.log("NOT OK!") - window.console.log(exported_string) - window.console.log(exported_string_2) + linenum = 1 + for line1, line2 in zip(exported_string.split("\n"), exported_string_2.split("\n")): + if line1 != line2: + window.console.log("Error on line {}".format(linenum)) + window.console.log(exported_string) + window.console.log(exported_string_2) + window.console.log("Error on line {}".format(linenum)) + break + linenum += 1 + + window.console.log("OK") + +def prettify_xml(source_xml): + xml_doc = __new__(DOMParser()).parseFromString(source_xml, 'application/xml'); + xslt_doc = __new__(DOMParser()).parseFromString("".join([ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '']), 'application/xml') + + xslt_processor = __new__(XSLTProcessor()) + xslt_processor.importStylesheet(xslt_doc) + result_doc = xslt_processor.transformToDocument(xml_doc) + result_xml = __new__(XMLSerializer()).serializeToString(result_doc) + + return result_xml