Prettify xml output
This commit is contained in:
@@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET
|
||||
import csv
|
||||
import datetime
|
||||
import os
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
@@ -182,24 +183,31 @@ while fileNameNotFound:
|
||||
if not os.path.exists(fileName):
|
||||
fileNameNotFound = False
|
||||
|
||||
|
||||
print()
|
||||
print(f'Fájl mentése ide: {fileName}')
|
||||
print()
|
||||
|
||||
# --------------------------------- Write xml -------------------------------- #
|
||||
# ------------------------------- Generate xml ------------------------------- #
|
||||
|
||||
data = ET.Element('Leolvasasok')
|
||||
data.tail = '\r\n'
|
||||
for mérő in allXmlData:
|
||||
currSub = ET.SubElement(data, 'Leolvasas')
|
||||
currSub.tail = '\r\n'
|
||||
for adat in mérő:
|
||||
a = ET.SubElement(currSub, adat)
|
||||
a.text = mérő[adat]
|
||||
a.tail = '\r\n'
|
||||
|
||||
print(ET.dump(data))
|
||||
xmlString = ET.tostring(data)
|
||||
|
||||
# ------------------------------- Prettify xml ------------------------------- #
|
||||
|
||||
bs_data = BeautifulSoup(xmlString, 'xml')
|
||||
prettyXml = bs_data.prettify()
|
||||
|
||||
print(prettyXml)
|
||||
print()
|
||||
|
||||
tree = ET.ElementTree(data)
|
||||
tree.write(fileName, encoding="utf-8", xml_declaration=True)
|
||||
# --------------------------------- Save file -------------------------------- #
|
||||
|
||||
f = open(fileName, "x")
|
||||
f.write(prettyXml)
|
||||
f.close
|
||||
Reference in New Issue
Block a user