Skip to content

Instantly share code, notes, and snippets.

@rpuntaie
Created February 22, 2018 10:23
Show Gist options
  • Save rpuntaie/caa77f718c6e5109cdd584029f0db43f to your computer and use it in GitHub Desktop.
Save rpuntaie/caa77f718c6e5109cdd584029f0db43f to your computer and use it in GitHub Desktop.
python function to convert the xml file generated by CppCheck into a text table
def cppcheck2tbl(filename):
"""
Takes the xml file generated by CppCheck
and converts it to a text table.
"""
import xml.etree.ElementTree as ET
import csv
import html
tree = ET.parse(filename)
root = tree.getroot()
def errors(root):
for err in root.findall('errors/error'):
loc = err.find('location')
yield [html.unescape(err.attrib[x]) for x in 'id severity msg'.split()]+[loc.attrib['file'],loc.attrib['line']]
tbl = '\n'.join(['\t\t'.join(x) for x in errors(root)])
del tree
return tbl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment