Friday, February 14, 2014

XML to Text transformation using smooks mediator

Smooks mediator can be used to apply transformations. Inputs can be provided as text/xml and smooks transformation resource has to be passed as an external resource.
Here is the sample smooks mediator configuration and smooks configuration which can be used to read an xml element from the input and parse it to a preferred output xml format.

Smooks meditaor config;

<smooks config-key="smooks">
               <input type="xml" expression="//csv/arg0"/>
               <output type="text"/>
            </smooks>


Sample request;

<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ >
 <soapenv:Body>
  <csv>
   <arg>1000,20130926,UAE</arg0>
  </csv>
 </soapenv:Body>
</soapenv:Envelope>

Smooks configuration;

<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
   <resource-config selector="org.xml.sax.driver">
    <resource>org.milyn.csv.CSVParser</resource>
    <param name="fields" type="string-list">RecordID,FileNumber,CorporationName</param>
  </resource-config>
</smooks-resource-list>

Output;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ax:text xmlns:ax="http://ws.apache.org/commons/ns/payload">
<csv-set>
<csv-record number="1">
<RecordID>1000</RecordID>
<FileNumber>00238374</FileNumber>
<CorporationName>UAE</CorporationName>
</csv-record>
</csv-set>
</ax:text>
</soapenv:Body>
</soapenv:Envelope>

No comments:

Post a Comment