Skip to content

Instantly share code, notes, and snippets.

@nbortolotti
Created January 8, 2015 05:25
Show Gist options
  • Save nbortolotti/0e075778fcb1425ba1a7 to your computer and use it in GitHub Desktop.
Save nbortolotti/0e075778fcb1425ba1a7 to your computer and use it in GitHub Desktop.
class xmlcsv:
def __init__(self, input_file, output_file, row, schema):
xml_file = open(input_file, "r")
col = schema
resultado = []
for _, element in etree.iterparse(xml_file, tag=row):
rows = list(element.iter('row'))
for row_element in rows:
row_tmp = []
a = 0
while a < len(col):
row_tmp.insert(a, row_element.get(col[a]))
a += 1
resultado.append(dict(zip(col, row_tmp)))
test_file = open(output_file, 'wb')
writer = UnicodeDictWriter(test_file, col)
writer.writerows(resultado)
test_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment