Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The primary goals of this example are to introduce you to the following:

  1. Transforming from csv file to xml.
  2. The Smooks configuration file.
  3. Executing the Smooks Transformation.

SVN - Download - Other Tutorials

Other Relevant Info:

To Build: "mvn clean install"
To Run: "mvn exec:java"

work in progress...

Transforming from csv file to xml

So here's the source csv file that is to be transformed:


And this is the expected result of our transformation:


The Smooks Configuration

In order to apply this transformer to a message fragment, a Smooks Configurationneeds to be created. This configuration will target the transformer at a particular message fragment. For more information on configuring XSLT resources, see XslContentDeliveryUnitCreator.

Here's the configuration ("smooks-config.xml"):

<?xml version="1.0"?>
<smooks-resource-list xmlns="">

	<!--Configure the CSVParser to parse the message into a stream of SAX events. -->
	<resource-config selector="org.xml.sax.driver">
		<param name="fields" type="string-list">firstname,lastname,gender,age,country</param>


Executing The Transformation

Again, it's exactly the same as with the java-basic tutorial:

Smooks smooks = new Smooks("smooks-config.xml");
StandaloneExecutionContext executionContext = smooks.createExecutionContext();
smooks.filter(new StreamSource(new InputStreamReader(new ByteArrayInputStream(messageIn), "UTF-8")), new StreamResult(writer), executionContext); 

Of course, you'd typically cache the Smooks instance.

See the example/ in the example source.

  • No labels