
Your elements named TrdCapRpt have attributes, if you have such node, its attribute node.attrib Use csv.DictWriter, get values from node.attrib dictionary Is there a easy way to export this to a CSV ? Spamwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) With open('/Users/anantsangar/Desktop/output.csv', 'w') as csvfile: Print RptID, TrdTyp, TrdSubTyp, TrdDt, BizDt, MLegRptTyp, MtchStat, MsgEvtSrc, TrdID, LastQty, LastPx, TxnTm, SettlCcy, SettlDt, PxSubTyp, VenueTyp, VenuTyp, OfstInst With open('/Users/testuser/Desktop/CMEREG1.XML', 'rt') as f: I have tried it with the following code but I can t get the right output: from xml.etree import ElementTree I have the following XML structure and I am trying to convert it into a csv in python: Īnd I am trying to convert this into a csv file.
