Skip to content

Commit

Permalink
Merge pull request #28 from poojanihalani/xml2csv_changes
Browse files Browse the repository at this point in the history
Xml2csv changes to handle multiple  sae xml keys in an object
  • Loading branch information
knadh committed Oct 9, 2015
2 parents 07386d9 + 1593563 commit 0a0cd3c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion xmlutils/xml2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def convert(self, tag="item", delimiter=",", ignore=[], noheader=False,
items = []
header_line = []
field_name = ''
processed_fields = []

tagged = False
started = False
Expand All @@ -73,14 +74,17 @@ def convert(self, tag="item", delimiter=",", ignore=[], noheader=False,
should_tag = not tagged and should_write and not noheader

if event == 'start':
if elem.tag==tag:
processed_fields=[]
if elem.tag == tag and not started:
started = True
elif should_tag:
# if elem is nested inside a "parent", field name becomes parent_elem
field_name = '_'.join((field_name, elem.tag)) if field_name else elem.tag

else:
if should_write:
if should_write and elem.tag not in processed_fields:
processed_fields.append(elem.tag)
if should_tag:
header_line.append(field_name) # add field name to csv header
# remove current tag from the tag name chain
Expand Down

0 comments on commit 0a0cd3c

Please sign in to comment.