Python Forum

Full Version: Multiple XML file covert to CSV output file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team,
I have a multiple XML file and I want to convert the Multiple XML data into CVS file with | separator it is used to stored into the database.
Could you pls let me the code in python.
Sample multiple xml file:-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StandingSettlementInstruction xmlns="http://www.service.cdds.cs.com/ssiData_2">
<StableChangeVersion>2</StableChangeVersion>
<Core>
<LocalId>0171375670</LocalId>
<EffectiveDate>2018-06-24T06:38:47.093-04:00</EffectiveDate>
<DataStatus>Active</DataStatus>
<InternalIdentifier>00000000-0000-0000-0000-000008180d98</InternalIdentifier>
</Core>
<Change>
<LastApprovedVersion>2</LastApprovedVersion>
<LatestReviewTime>2018-06-24T06:38:47.013-04:00</LatestReviewTime>
</Change>
<SystemCodes>
<SystemCodeType>
<Id>NTPA</Id>
</SystemCodeType>
<Value>Y37F40</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<LatestReviewers>
<userName>msiepra</userName>
</LatestReviewers>
<TradingAccount>
<Core>
<LocalId>0170485038</LocalId>
</Core>
<SystemCodes>
<SystemCodeType>
<Id>TradingAccountGSID</Id>
</SystemCodeType>
<Value>4973662</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<SystemCodes>
<SystemCodeType>
<Id>NTPA</Id>
</SystemCodeType>
<Value>Y37F40</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<SystemCodes>
<SystemCodeType>
<Id>FXOPs</Id>
</SystemCodeType>
<Value>L61774</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<SystemCodes>
<SystemCodeType>
<Id>SDSFB</Id>
</SystemCodeType>
<Value>MARSH38LONGB</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
</TradingAccount>
<Country>
<IsoCode>DE</IsoCode>
</Country>
<Security>
<Id>COB</Id>
</Security>
<SettlementMethod>
<Id>EURO_CLEAR</Id>
</SettlementMethod>
<Currency>
<IsoCode>EUR</IsoCode>
</Currency>
<DefaultSsi>true</DefaultSsi>
<TermsOfDelivery>
<Id>FOP</Id>
</TermsOfDelivery>
<SettlementType>NON_CASH</SettlementType>
<ClassOfAccount>BOTH</ClassOfAccount>
<SettlementChainEntries>
<StepType>NonCashDeagReag</StepType>
<IdentifierType>
<Id>SWIFT_BIC</Id>
</IdentifierType>
</SettlementChainEntries>
<SettlementChainEntries>
<StepType>NonCashDecuRecu</StepType>
<IdentifierType>
<Id>SWIFT_BIC</Id>
</IdentifierType>
</SettlementChainEntries>
<SettlementChainEntries>
<StepType>NonCashPset</StepType>
<Bic>MGTCBEBEECL</Bic>
<AccountNumber>47950</AccountNumber>
<IdentifierType>
<Id>SWIFT_BIC</Id>
</IdentifierType>
</SettlementChainEntries>
<RecDel>BOTH</RecDel>
<CptyFirm>CPTY</CptyFirm>
<CountryOfSettlement/>
<SettleTypeOverride>
<Id>EE</Id>
</SettleTypeOverride>
</StandingSettlementInstruction>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StandingSettlementInstruction xmlns="http://www.service.cdds.cs.com/ssiData_2">
<StableChangeVersion>5</StableChangeVersion>
<Core>
<LocalId>0159515092</LocalId>
<EffectiveDate>2015-04-27T00:00:00.000-04:00</EffectiveDate>
<ClosingDate>2018-07-11T18:00:56.487-04:00</ClosingDate>
<DataStatus>Closed</DataStatus>
<InternalIdentifier>00000000-0000-0000-0000-00000302953a</InternalIdentifier>
</Core>
<Change>
<LastApprovedVersion>5</LastApprovedVersion>
<LatestReviewTime>2018-07-11T18:00:56.487-04:00</LatestReviewTime>
</Change>
<SystemCodes>
<SystemCodeType>
<Id>NTPANY</Id>
</SystemCodeType>
<Value>2YVED0</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<SystemCodes>
<SystemCodeType>
<Id>NTPA</Id>
</SystemCodeType>
<Value>YXWZS0</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<LatestReviewers>
<userName>AlertDownloader</userName>
</LatestReviewers>
<TradingAccount>
<Core>
<LocalId>0159514367</LocalId>
</Core>
<SystemCodes>
<SystemCodeType>
<Id>TradingAccountGSID</Id>
</SystemCodeType>
<Value>4770729</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<SystemCodes>
<SystemCodeType>
<Id>NTPANY</Id>
</SystemCodeType>
<Value>2YVED0</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
<SystemCodes>
<SystemCodeType>
<Id>NTPA</Id>
</SystemCodeType>
<Value>YXWZS0</Value>
<ValueStatus>Active</ValueStatus>
</SystemCodes>
</TradingAccount>
<Country>
<IsoCode>MX</IsoCode>
</Country>
<Security>
<Id>EQU</Id>
</Security>
<SettlementMethod>
<Id>INDEVAL</Id>
</SettlementMethod>
<AlertIndex>1</AlertIndex>
<Currency>
<IsoCode>MXN</IsoCode>
</Currency>
<DefaultSsi>true</DefaultSsi>
<TermsOfDelivery>
<Id>DVP</Id>
</TermsOfDelivery>
<SettlementType>NON_CASH</SettlementType>
<ClassOfAccount>BOTH</ClassOfAccount>
<SettlementChainEntries>
<StepType>NonCashPset</StepType>
<Bic>INDEMXMMXXX</Bic>
<IdentifierType>
<Id>SWIFT_BIC</Id>
</IdentifierType>
</SettlementChainEntries>
<SettlementChainEntries>
<StepType>NonCashDeagReag</StepType>
<SettlementAgentName>CITIBANK, MEXICO</SettlementAgentName>
<Bic>CITIUS33MER</Bic>
<AccountNumber>229347</AccountNumber>
<IdentifierType>
<Id>SWIFT_BIC</Id>
</IdentifierType>
</SettlementChainEntries>
<SettlementChainEntries>
<StepType>NonCashDecuRecu</StepType>
<SettlementAgentName>STATE STREET BANK AND TRUST COMPANY</SettlementAgentName>
<Bic>SBOSUS3CXXX</Bic>
<IdentifierType>
<Id>SWIFT_BIC</Id>
</IdentifierType>
</SettlementChainEntries>
<RecDel>BOTH</RecDel>
<CptyFirm>CPTY</CptyFirm>
</StandingSettlementInstruction>.



I want the data in the XML to output CSV file. like

SystemCodes|LastApprovedVersion|LocalId|EffectiveDate|DataStatus|InternalIdentifier|TradingAccountLocalId|StableChangeVersion,
Y37F40|2|0171375670|2018-06-24T06:38:47.093-04:00|Active|00000000-0000-0000-0000-000008180d98|0170485038|2
What have you tried? And please read the BBCode link in my signature below before posting your code.