18 lines
508 B
Python
18 lines
508 B
Python
import xmltodict
|
|
import json
|
|
|
|
|
|
def xml_to_json(xml: str, pretty_formatting: bool) -> str:
|
|
xml_dict = xmltodict.parse(xml)
|
|
indent = 4 if pretty_formatting else None
|
|
json_str = json.dumps(xml_dict, ensure_ascii=False, indent=indent)
|
|
return json_str
|
|
|
|
|
|
if __name__ == "__main__":
|
|
file = open('schedule.xml', encoding='utf8')
|
|
content = file.read()
|
|
result = xml_to_json(content, True)
|
|
file = open('schedule.json', 'w', encoding='utf8')
|
|
file.writelines(result)
|
|
print(result)
|