Skip to content

Instantly share code, notes, and snippets.

@bmwalters
Created February 18, 2018 21:17
Show Gist options
  • Save bmwalters/48d16125983fd6726616018b5114f6a4 to your computer and use it in GitHub Desktop.
Save bmwalters/48d16125983fd6726616018b5114f6a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import xml.etree.ElementTree as ElementTree
tree = ElementTree.parse("Resources.resx")
datas = sorted(map(lambda x: (x, len(x.find("value").text)), tree.getroot().findall("data")), key=lambda x: x[1])
if not os.path.isdir("Split_out/"):
os.mkdir("Split_out/")
for data in datas:
# if data[1] > (1024*512): # 0.5KiB
if not ("mimetype" in data[0].attrib):
tree.getroot().remove(data[0])
newroot = ElementTree.Element("data")
newroot.append(data[0])
subtree = ElementTree.ElementTree(newroot)
name = data[0].attrib["name"]
subtree.write(f"Split_out/{name}.xml")
tree.write("Resources_new.resx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment