Skip to content

Instantly share code, notes, and snippets.

@tsibley
Created November 9, 2024 04:00
Show Gist options
  • Save tsibley/fb78fb8c6c6db1a9dea7473c606f5868 to your computer and use it in GitHub Desktop.
Save tsibley/fb78fb8c6c6db1a9dea7473c606f5868 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import xml.etree.ElementTree as ET
from sys import argv, stdin, stdout
layer = argv[1]
doc = ET.parse(stdin)
root = doc.getroot()
for g in root.findall(".//{http://www.w3.org/2000/svg}g[@id]"):
id = g.get("id")
if id and id.startswith("layer-") and id not in {"layer-base", f"layer-{layer}"}:
root.remove(g)
doc.write(stdout, encoding = "unicode", xml_declaration = True)
@tsibley
Copy link
Author

tsibley commented Nov 9, 2024

doesn't preserve formatting, namespace names, etc. so less helpful than the alternative yq + jq approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment