Merge pull request #286 from Cockatrice/tooomm-xml_declaration

Fix XML declaration
This commit is contained in:
ebbit1q 2022-02-06 01:55:48 +01:00 committed by GitHub
commit f17023cf47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -208,8 +208,7 @@ def open_header(card_xml_file: IO[Any]) -> None:
:param card_xml_file: Card file path
"""
card_xml_file.write(
"<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<cockatrice_carddatabase version='3'>\n"
"<cockatrice_carddatabase version='3'>\n"
+ " <!--\n"
+ " Created At: "
+ datetime.datetime.utcnow().strftime("%a, %b %d %Y, %H:%M:%S")
@ -255,11 +254,11 @@ def close_xml_file(card_xml_file: IO[Any]) -> None:
card_xml_file.write("</cards>\n</cockatrice_carddatabase>\n")
card_xml_file.close()
# Make the files pretty
# Make the files pretty and add xml declaration
parser = etree.XMLParser(remove_blank_text=True)
root = etree.parse(card_xml_file.name, parser).getroot()
with pathlib.Path(card_xml_file.name).open("wb") as f:
f.write(etree.tostring(root, pretty_print=True))
f.write(etree.tostring(root, encoding="UTF-8", xml_declaration=True, pretty_print=True))
def xml_escape(text):