CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Convert CSV file to nested XML file using PERL?

 



karthic
New User

Jun 30, 2015, 3:55 PM

Post #1 of 1 (1956 views)
Convert CSV file to nested XML file using PERL? Can't Post

We have a CSV file which i need to convert to XML file using Perl or Unix shell scripting.

I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML hierarchically by avoiding the duplicate values. Please take a look into the XML file below.

Input data below:-

RLTP_ID,RLTP_NAME,PROD_ID,PROD_NAME,CUST_ID,CUST_NAME,ACC_ID,ACC_NAME,ACC_BALANCE,TXN_ID,TXN_AMT,ACC_TYPE,ACC_CODE,TXN_CODE
10,Phil,1,Personal,2,Fixed,3,Savings,3000,4,500,X,YY,11
10,Phil,1,Personal,2,Fixed,3,Savings,3000,4,500,X,YY,12
10,Phil,1,Personal,2,Fixed,3,Savings,3000,4,500,X,ZZ,11
10,Phil,1,Personal,2,Fixed,3,Savings,3000,4,500,X,ZZ,12
10,Phil,1,Personal,2,Fixed,7,Savings,3000,8,500,X,AA,11
10,Phil,1,Personal,2,Fixed,7,Savings,3000,8,500,X,AA,12
10,Phil,1,Personal,2,Fixed,7,Savings,3000,8,500,X,AA,13
10,Phil,1,Personal,2,Fixed,7,Savings,3000,8,500,X,BB,11
10,Phil,1,Personal,2,Fixed,7,Savings,3000,8,500,X,BB,12
10,Phil,1,Personal,2,Fixed,7,Savings,3000,8,500,X,BB,13

XML File:-

<transactiondetails>
<rltp_id>10</rltp_id>
<rltp_name>Phil</rltp_name>
<product>
<prod_id>1</prod_id>
<prod_name>Personal</prod_name>
<customer>
<cust_id>2</cust_id>
<cust_name>Fixed</cust_name>
<account>
<acc_id>3</acc_id>
<acc_name>Savings</acc_name>
<acc_balance>3000</acc_balance>
<acc_type>X</acc_type>
<acc_code>ZZ</acc_code>
<acc_code>YY</acc_code>
<transaction>
<txntrack>
<txn_id>4</txn_id>
<txn_amt>500</txn_amt>
<txn_code>11</txn_code>
<txn_code>12</txn_code>
</txntrack>
</transaction>
<transaction>
<txntrack>
<txn_id>5</txn_id>
<txn_amt>500</txn_amt>
<txn_code/>
</txntrack>
</transaction>
<transaction>
<txntrack>
<txn_id>6</txn_id>
<txn_amt>500</txn_amt>
<txn_code/>
</txntrack>
</transaction>
</account>
<account>
<acc_id>7</acc_id>
<acc_name>Savings</acc_name>
<acc_balance>3000</acc_balance>
<acc_type>X</acc_type>
<acc_code>AA</acc_code>
<acc_code>BB</acc_code>
<transaction>
<txntrack>
<txn_id>8</txn_id>
<txn_amt>500</txn_amt>
<txn_code>11</txn_code>
<txn_code>12</txn_code>
<txn_code>13</txn_code>
</txntrack>
</transaction>
</account>
</customer>
</product>
</transactiondetails>

Code



      
    

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives