Skip to content

Instantly share code, notes, and snippets.

@prozacchiwawa
Created April 16, 2021 22:31
Show Gist options
  • Save prozacchiwawa/ec719fd1139872ddc9e04ff7a1855da6 to your computer and use it in GitHub Desktop.
Save prozacchiwawa/ec719fd1139872ddc9e04ff7a1855da6 to your computer and use it in GitHub Desktop.
import xml.dom.minidom
import sys
def traverse(e,o):
oldwhere = None
useo = dict(o.items())
if e.nodeType == e.TEXT_NODE:
return
nodeinfo = {}
attrs = e.getElementsByTagName('attributelist')[0]
for a in attrs.childNodes:
if a.nodeType == a.TEXT_NODE:
continue
nodeinfo[a.getAttribute('name')] = a.getAttribute('value')
if e.tagName == 'include':
useo['where'] = nodeinfo['name']
else:
if 'kind' in nodeinfo and nodeinfo['name'] == o['find']:
print(o['where'])
for n in e.childNodes:
if n.nodeType == n.TEXT_NODE:
continue
if n.tagName == "attributelist":
continue
traverse(n,useo)
if __name__ == '__main__':
doc = xml.dom.minidom.parse(sys.argv[1])
traverse(doc.documentElement, {'find':sys.argv[2]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment