Skip to content

Instantly share code, notes, and snippets.

@srcreigh
Last active November 3, 2015 00:47
Show Gist options
  • Save srcreigh/9d32f34328eccaa0534f to your computer and use it in GitHub Desktop.
Save srcreigh/9d32f34328eccaa0534f to your computer and use it in GitHub Desktop.
from xml.dom import minidom
import json
xmldoc = minidom.parse('changelogs.xml')
items = []
itemsxml = xmldoc.getElementsByTagName('string-array')
versions = itemsxml[0].getElementsByTagName('item')
dates = itemsxml[1].getElementsByTagName('item')
descs = itemsxml[2].getElementsByTagName('item')
def GetValue(thing):
return thing.firstChild.nodeValue
for i in range(0,len(versions)):
item = {}
item['version_name'] = GetValue(versions[i])
item['release_date'] = GetValue(dates[i])
changes = GetValue(descs[i]).split('\\n')
for j in range(0,len(changes)):
if j == 0:
changes[j] = changes[j][4:]
elif j == len(changes)-1:
changes[j] = changes[j][3:-1]
else:
changes[j] = changes[j][3:]
item['changes'] = changes
items.append(item)
print json.dumps(items[::-1], indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment