#!/usr/bin/env python import xml.etree.ElementTree as ET doc = ET.parse('valgrind.xml') errors = doc.findall('//error') out = open("cpputest_valgrind.xml","w") out.write('\n') out.write('\n') errorcount=0 for error in errors: errorcount=errorcount+1 kind = error.find('kind') what = error.find('what') if what == None: what = error.find('xwhat/text') stack = error.find('stack') frames = stack.findall('frame') for frame in frames: fi = frame.find('file') li = frame.find('line') if fi != None and li != None: break if fi != None and li != None: out.write(' \n') else: out.write(' \n') out.write(' \n') out.write(' '+what.text+'\n\n') for frame in frames: ip = frame.find('ip') fn = frame.find('fn') fi = frame.find('file') li = frame.find('line') bodytext = fn.text bodytext = bodytext.replace("&","&") bodytext = bodytext.replace("<","<") bodytext = bodytext.replace(">",">") if fi != None and li != None: out.write(' '+ip.text+': '+bodytext+' ('+fi.text+':'+li.text+')\n') else: out.write(' '+ip.text+': '+bodytext+'\n') out.write(' \n') out.write(' \n') out.write('\n') out.close()