简体   繁体   中英

How to convert CSV to XML with Mapforce and Mule

I have generated a java transform with Mapforce from CSV to XML and I'd like to use it with Mule but I don't know how.

The Mapforce IDE generates a console app that calls the transform and it looks like below but I can't figure out how to us this transform in a mule flow.

Can you?

INPUT CSV:

"";"208556";"ABC123";"HASK";46;"2659307019";"MMM505";15000.00;10000.00;"160100";"Beh. avg. Brännbart avfall";"1000040";"Svensk Säkerhetsvideo AB";"Nytorpsvägen 4";"20161101";"122739"

and output XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<uppdrag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:/Users/CLAES/SkyDrive/HANSAN~1/INTEGRATIONSPROJEKT/SkövdeIntegration/TESTDATA/20161031-1.xsd">
<kund>208556</kund>
<littra>1000040</littra>
<Arb_plats_ID>HASK</Arb_plats_ID>
<transaktionsid>46</transaktionsid>
<viktin>15000</viktin>
<viktut>10000</viktut>
<fraktion_ID>160100</fraktion_ID>
<fraktion_namn/>
<datum>20161101</datum>
<tid>122739</tid>
<regnr>ABC123</regnr>

JAVA Class from Mapforce:

public class MappingConsole {
    public static void main(String[] args) {
        System.out.println("Mapping Application");

        try { // Mapping
            TraceTargetConsole ttc = new TraceTargetConsole();

            MappingMapTo20161031_1 MappingMapTo20161031_1Object = new MappingMapTo20161031_1();

            MappingMapTo20161031_1Object.registerTraceTarget(ttc);

            {
                com.altova.io.Input Text_file2Source = com.altova.io.StreamInput.createInput("C:/Users/CLAES/SkyDrive/Hans Andersson/INTEGRATIONSPROJEKT/Sk\u00F6vdeIntegration/Datamodell/textfil med rubriker.txt");
                com.altova.io.Output Name20161031_12Target = new com.altova.io.FileOutput("C:/Users/CLAES/SkyDrive/Hans Andersson/INTEGRATIONSPROJEKT/Sk\u00F6vdeIntegration/TESTDATA/20161031-1.xml");

                MappingMapTo20161031_1Object.run(
                        Text_file2Source,
                        Name20161031_12Target);
            }
            System.out.println("Finished");
        } 
    }
}

Take the java code from your main method and use it in a custom java transformer. Details on creating custom Java transformers available in the docs such as here: https://docs.mulesoft.com/mule-user-guide/v/3.7/creating-custom-transformer-classes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM