1

I have a proxy on ESB that receives an XML payload, and I need to send this payload to another software that only accepts CSV files.

So I need to transform this XML payload to CSV file, but using Smooks. I know how to transform CSV to XML, but the opposite I can't find anything on web. When I try to create it on Developer Studio there's no option to CSV output file.

I know how to transform XML to CSV using XSLT transformation, but my volumetry is huge and I think Smooks is better than XSLT in this case.

Community
  • 1
  • 1

1 Answers1

0

In Smooks 1.7, you can use the FreeMarker cartridge to transform from XML to CSV:

<?xml version='1.0' encoding='UTF-8'?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                      xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd">

    <resource-config selector="record">
        <resource>org.milyn.delivery.DomModelCreator</resource>
    </resource-config>

    <ftl:freemarker applyOnElement="record">
        <ftl:template>account.ftl</ftl:template>
    </ftl:freemarker>

</smooks-resource-list>

The FreeMarker visitor cannot read directly off the XML stream so the DOM visitor needs to be configured such that it creates DOMs from record elements found within the input stream. The account.ftl template could be as follows:

<#ftl ns_prefixes={"ossandme":"http://ossandme.org"}>
${record['ossandme:First_Name']}~${record['ossandme:Last_Name']}~${record['ossandme:ShippingStreet']}~${record['ossandme:ShippingCity']}~${record['ossandme:ShippingState']}~${record['ossandme:ShippingPostalCode']}~${record['ossandme:Member_Tier__c']}

Source: https://oncodesign.io/2014/09/16/the-trials-of-smooks/

Claude
  • 489
  • 4
  • 15