def __handleArrayElement__(arrayElement): a = [] child = xmlutil.firstChildElement(arrayElement) while child is not None: a.append(__handleValueElement__(child)) child = xmlutil.nextSiblingElement(child) return a
def __handleDictElement__(dictElement): d = dict() for keyElement in xmlutil.getChildrenByTagName(dictElement, 'key'): key = keyElement.firstChild.data valueElement = xmlutil.nextSiblingElement(keyElement) d[key] = __handleValueElement__(valueElement) return d
def __parseItunesXml__(xmlFile): xmldoc = minidom.parse(xmlFile) assert xmldoc.documentElement.tagName == 'plist' rootDictElement = xmlutil.getChildrenByTagName(xmldoc.documentElement, 'dict').next() assert xmlutil.nextSiblingElement(rootDictElement) == None rootDict = __handleDictElement__(rootDictElement) tracksDict = rootDict['Tracks'] return tracksDict