This example demonstrates how Groovy can be used to perform Fragment based Transforms through Smooks. SVN - Download To Build: "mvn clean install" See Mixing DOM and SAX Models with Smooks OverviewIn this example, we want to modify the "supplies" category in a Shopping list message, adding 2 to the quantity, where the item is "Pens". The Input MessageThe input message is a Shopping list: <shopping> The Smooks ConfigurationTo do this, we write a simple little Groovy script and target it at the <category> elements in the message. The script simply iterates over the <item> elements in the category and increments the quantity by 2, where the category type is "supplies" and the item is "Pens": <?xml version="1.0"?> The result of running this transform on the specified input message will simply modify the quantity value on the "Pens" item from 4 to 6. Executing Smooksprotected static String runSmooksTransform(Reader messageIn) throws IOException, SAXException, SmooksException {
Of course, you'd typically cache the Smooks instance, and if the Result was potentially a huge message, then you'd more likely stream the result to a file (for example). See the example/Main.java in the example source. |