Fixed export
This commit is contained in:
@@ -7,6 +7,7 @@ import multiprocessing
|
||||
import os
|
||||
import traceback
|
||||
import urllib.parse
|
||||
import xml.dom.minidom
|
||||
from collections import defaultdict
|
||||
from datetime import date, datetime
|
||||
from functools import partial
|
||||
@@ -1323,7 +1324,16 @@ async def handle_xml_upload(
|
||||
extension = Path(filename).suffix or ".xml"
|
||||
log_filename = logs_dir / f"{base_filename}_{username}_{timestamp}{extension}"
|
||||
|
||||
# Save XML content to file
|
||||
# Format and save XML content to file
|
||||
try:
|
||||
dom = xml.dom.minidom.parseString(xml_content)
|
||||
pretty_xml = dom.toprettyxml(indent=" ")
|
||||
# Remove extra blank lines that toprettyxml adds
|
||||
pretty_xml = "\n".join([line for line in pretty_xml.split("\n") if line.strip()])
|
||||
log_filename.write_text(pretty_xml, encoding="utf-8")
|
||||
except Exception as e:
|
||||
# If formatting fails, save the original content
|
||||
_LOGGER.warning("Failed to format XML: %s. Saving unformatted.", str(e))
|
||||
log_filename.write_text(xml_content, encoding="utf-8")
|
||||
|
||||
_LOGGER.info(
|
||||
|
||||
Reference in New Issue
Block a user