Created
February 24, 2025 14:47
-
-
Save epoz/4886478af35885fe1ba2ff8a16e5249d to your computer and use it in GitHub Desktop.
Convert a LIDO.xml file into a zipfile with each element a separate file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, zipfile, os, time | |
from xml.etree import ElementTree as ET | |
for filename in os.listdir("."): | |
if not filename.endswith(".xml"): | |
continue | |
print(f"{time.ctime()} Parsing {filename}") | |
zf = zipfile.ZipFile(f"{filename}.zip", "w") | |
print(f"{time.ctime()} Writing {filename}.zip") | |
doc = ET.parse(filename) | |
count = 0 | |
for element in doc.findall("{http://www.lido-schema.org}lido"): | |
buf = ET.tostring(element) | |
zf.writestr(f"{count}.xml", buf) | |
count += 1 | |
zf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment