Better support for UTF-8 in XML output.

From SchrodingersGat/KiBoM#129 and SchrodingersGat/KiBoM#130
Fixes problems on Windows 10
This commit is contained in:
Salvador E. Tropea 2020-08-06 08:59:25 -03:00
parent 7563d1a9ad
commit 3555059f8f
1 changed files with 4 additions and 2 deletions

View File

@ -45,8 +45,10 @@ def write_xml(filename, groups, headings, head_names, cfg):
attrib[h] = str(row[i])
ElementTree.SubElement(xml, "group", attrib=attrib)
with open(filename, "wt") as output:
# Most of the UTF-8 enforcement here is for Windows
# Selecting it in the tostring call is enough for Linux
with open(filename, "wt", encoding="utf-8") as output:
out = ElementTree.tostring(xml, encoding="utf-8")
output.write(minidom.parseString(out).toprettyxml(indent="\t"))
output.write(minidom.parseString(out).toprettyxml(indent="\t", encoding="utf-8").decode("utf-8"))
return True