Skip to content

Instantly share code, notes, and snippets.

@epoz
Created February 24, 2025 14:47
Show Gist options
  • Save epoz/4886478af35885fe1ba2ff8a16e5249d to your computer and use it in GitHub Desktop.
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
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