2020-01-05 08:54:38 +00:00
|
|
|
from export import export_to_xml
|
|
|
|
from browser import window
|
|
|
|
|
|
|
|
|
2019-11-20 18:15:05 +00:00
|
|
|
def clean_label(label):
|
|
|
|
return label.replace("-- ", "")
|
2020-01-05 08:54:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_export(model):
|
2020-01-21 21:19:28 +00:00
|
|
|
exported_string = prettify_xml(export_to_xml(model))
|
2020-01-05 08:54:38 +00:00
|
|
|
model.import_xml(exported_string)
|
2020-01-21 21:19:28 +00:00
|
|
|
exported_string_2 = prettify_xml(export_to_xml(model))
|
2020-01-05 08:54:38 +00:00
|
|
|
|
2020-01-21 21:19:28 +00:00
|
|
|
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([
|
|
|
|
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">',
|
|
|
|
' <xsl:strip-space elements="*"/>',
|
|
|
|
' <xsl:template match="para[content-style][not(text())]">',
|
|
|
|
' <xsl:value-of select="normalize-space(.)"/>',
|
|
|
|
' </xsl:template>',
|
|
|
|
' <xsl:template match="node()|@*">',
|
|
|
|
' <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>',
|
|
|
|
' </xsl:template>',
|
|
|
|
' <xsl:output indent="yes"/>',
|
|
|
|
'</xsl:stylesheet>']), '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
|