Last active
May 29, 2018 09:40
-
-
Save wrenoud/9a7203b56d18bc46486ccea58635ec4c to your computer and use it in GitHub Desktop.
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 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