we have a CSV which i need to convert to XML 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>
Any idea would be great. Thank you.
---------- Post updated at 06:56 AM ---------- Previous update was at 04:14 AM ----------
im writing a shell script with nested for loop or nested while loop to generate this XML file. Please let me know if there is any other efficient way to process this CSV file. this CSV file contains total 20 million records. As you know looping through the 20 million records will take much time.
Appreciate your help.