0

I'm new to Mule, so bear with me. I have the following CSV file that I receive:

Company1,2,123 Street,Winchester,UK
"000010","CHRISTINE","I","HAAS","A00","3978","1995-01-01","PRES",18,"F","1963-08-24",152750.00
"000020","MICHAEL","L","THOMPSON","B01","3476","2003-10-10","MANAGER",18,"M","1978-02-02",94250.00

The first line, header, contains company info plus the number of records (number of employees) in CSV file (second parm in the header).

Now I need to convert it to the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<tns:employeedata xmlns:tns="http://coxb.test.legstar.com/payrollemployee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://coxb.test.legstar.com/payrollemployee PayrollEmployee.xsd ">
  <tns:employeecount>2</tns:employeecount>
  <tns:employeelist>
    <tns:employees>
      <tns:employeenumber>000010</tns:employeenumber>
      <tns:firstname>CHRISTINE</tns:firstname>
      <tns:middleinitial>I</tns:middleinitial>
      <tns:surname>HAAS</tns:surname>
      <tns:department>A00</tns:department>
    </tns:employees>
    <tns:employees>
      <tns:employeenumber>000020</tns:employeenumber>
      <tns:firstname>MICHAEL</tns:firstname>
      <tns:middleinitial>L</tns:middleinitial>
      <tns:surname>THOMPSON</tns:surname>
      <tns:department>B01</tns:department>
    </tns:employees>
  </tns:employeelist>
</tns:employeedata>

I could easily transform this file without the first line (header). My problem is how to process the header and extract/transform "employeecount".

Any help will be greatly appreciated.

Alex N
  • 1

1 Answers1

0

The easiest way to do this is to use DataMapper. Set the input to CSV (using a sample CSV) and the output to XML (using your XSD or a sample XML).

Once you're in the mapping view, click on your employeecount field. You'll see an area where you can enter an expression. There is a non-documented parameter $in.0.__id which you can use which will contain the record count. Note that this will only work for CSV files.

Regarding how to skip the first line, DataMapper does this by default.

DarkAjax
  • 15,955
  • 11
  • 53
  • 65
  • Thank you Dan. I tried what you suggested and it works half way. What I get as a result of my mapping is this: – Alex N Mar 12 '13 at 13:15
  • Thank you Dan. I tried what you suggested and it works half way. What I get as a result of my mapping is multiple root XML structures "employeedata" with a single "employees" element and "employeecount" field incremented by one in each new entry in the output XML (similar to loop output in java). I don't get one root element "employeedata" with a nested list of "employees" and one element for "employeecount". I'm not sure if it is my inability to properly use DataMapper, or the tool works "as designed". – Alex N Mar 12 '13 at 13:27