Link to home
Start Free TrialLog in
Avatar of meninga
meninga

asked on

Using SSIS to convert csv to xml

I have a sample CSV file containg data in the following format:

CandidateID,CQN,CentreCode,ExamRef,Forename,Surname,Middlename,DOB,Gender
123456,ABC123,A0001CZ,XYZ123,Joe,Blogs,,21/02/1990,M
123456,ABC124,A0001CZ,XYZ987,Joe,Blogs,,21/02/1990,M
123457,ABC125,B0006CZ,XYZ123,Jane,Blogs,,18/05/1990,F
123457,ABC126,B0006CZ,XYZ987,Jane,Blogs,,18/05/1990,F

I need to convert this csv data into xml format which will provide the xml source for an SSIS package I have written. The xml source needs to be in the following format:

<data>
 <user>
   <id>0</id>
   <forename>Dave</forename>
   <surname>Dixon</surname>
   <middleName>Wakefield</middleName>
   <dob>07/10/1982</dob>
   <gender>M</gender>
   <addressLine1>31 Marlborough Road</addressLine1>
   <addressLine2/>
   <town>Shipley</town>
   <county>7</county>
   <country>0</country>
   <postCode>BD18 3NX</postCode>
   <telephone>22222</telephone>
   <email>example@test.com</email>
   <ethnicOrigin>0</ethnicOrigin>
   <accountExpiryDate>07/03/2009</accountExpiryDate>
   <username>user_xyz</username>
   <extraInfo>
     <specialRequirements/>
   </extraInfo>
   <specialRequirements/>
   <candidateRef>xyz</candidateRef>
   <centreRoles>
     <centre id="1">
       <added>
         <i>6</i>
       </added>
       <removed/>
     </centre>
   </centreRoles>
   <centres>
     <added/>
     <removed/>
   </centres>
   <qualifications>
     <added/>
     <removed/>
   </qualifications>
   <retired>0</retired>
 </user>
</data>

Is it possible to transform the CSV data to XML in SSIS? Thanks
Avatar of srnar
srnar

Yes it is possible. You can import the CSV into a SQL Server table and then use SELECT FOR XML AUTO statement. Try this link:

msdn defintion
http://msdn.microsoft.com/en-us/library/ms173812.aspx

Longer text from magazin:
http://msdn.microsoft.com/en-us/library/aa175790(SQL.80).aspx
Avatar of meninga

ASKER

Thanks smar. I want to avoid using a staging table so I've worked out how to transform the data using the Script Component. This XML now complies to the format required to execute a stored procedure.
Congratulations. Do you mean SSIS Script task? In version 2005 it can be coded only in VB.NET - it has nothing to do with C#.
ASKER CERTIFIED SOLUTION
Avatar of meninga
meninga

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial