cancel
Showing results for 
Search instead for 
Did you mean: 

Convert CSV to XML in CPI

0 Kudos

Hi Experts

I am trying to convert an input from a CSV file to XML in an iFlow in CPI.

Input.

OrgNo;OrgName;EmpNo;EmpName;EmpRole;EmpCell;EmpEmail

10001;TSB;20001;Jack Bones;Developer;481451;jb@csv.com

10001;TSB;20002;Martha Jackson;Analyst;445512;mj@csv.com

10002;Appletic; 20003;John Graham;Tester;885546;jg@xml.com

Expected Output:

<CSV_Organization>

<Organization>

<OrgNo>10001</OrgNo>

<OrgName>TSB</OrgName>

<Employee>

<EmpNo>20001</EmpNo>

<EmpName>Jack Bone</EmpName>

<EmpRole>Developer</EmpRole>

<EmpCell>481451</EmpCell>

<EmpEmail>jb@csv.com</EmpEmail>

</Employee>

</Organization>

<Organization>

<OrgNo>10001</OrgNo>

<OrgName>TSB</OrgName>

<Employee>

<EmpNo>20002</EmpNo>

<EmpName>Martha Jackson</EmpName>

<EmpRole>Analyst</EmpRole>

<EmpCell>445512</EmpCell>

<EmpEmail>mj@csv.com</EmpEmail>

</Employee>

</Organization>

<Organization>

<OrgNo>10002</OrgNo>

<OrgName>Appletic</OrgName>

<Employee>

<EmpNo>20003</EmpNo>

<EmpName>John Graham</EmpName>

<EmpRole>Tester</EmpRole>

<EmpCell>885546</EmpCell>

<EmpEmail>jg@xml.com</EmpEmail>

</Employee>

</Organization>

</CSV_Organization>

The XSD file:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="CSV_Organization">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Organization" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:short" name="OrgNo"/>
              <xs:element type="xs:string" name="OrgName"/>
              <xs:element name="Employee">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:short" name="EmpNo"/>
                    <xs:element type="xs:string" name="EmpName"/>
                    <xs:element type="xs:string" name="EmpRole"/>
                    <xs:element type="xs:int" name="EmpCell"/>
                    <xs:element type="xs:string" name="EmpEmail"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

When I check the payload after conversion, The Only the inforamation passed through is the organisation fields, nothing is passed for the employee.

May please assist on how I could go about in achieving such an output.

Thanks

Muzi

Accepted Solutions (1)

Accepted Solutions (1)

former_member194481
Participant
0 Kudos

Hi,

Use this in xsd in csv to xml converter.

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CSV_Organization">
<xs:complexType>
<xs:sequence>
<xs:element name="Organization">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="OrgNo"/>
<xs:element type="xs:string" name="OrgName"/>
<xs:element type="xs:byte" name="EmpNo"/>
<xs:element type="xs:string" name="EmpName"/>
<xs:element type="xs:string" name="EmpRole"/>
<xs:element type="xs:byte" name="EmpCell"/>
<xs:element type="xs:string" name="EmpEmail"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

and after that do a small mapping

then u will get the desire output

Answers (0)