Skip to content

Instantly share code, notes, and snippets.

@wrenoud
Last active May 29, 2018 09:40
Show Gist options
  • Save wrenoud/9a7203b56d18bc46486ccea58635ec4c to your computer and use it in GitHub Desktop.
Save wrenoud/9a7203b56d18bc46486ccea58635ec4c to your computer and use it in GitHub Desktop.
import xml.dom
import xml.dom.minidom
def childelements(parentnode):
for node in parentnode.childNodes:
if node.nodeType != xml.dom.Node.ELEMENT_NODE:
continue
yield node
def childlayers(parentnode):
"""yields child nodes that are elements with the tag name 'g'"""
for node in childelements(parentnode):
if node.tagName != "g":
continue
yield node
with xml.dom.minidom.parse(svgpath) as dom:
svg = dom.getElementsByTagName("svg")[0]
for layer in childlayers(svg):
pass
# ...
dom.writexml(outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment