March 28, 2006

Try using FreeMarker to generate XML documents

Generating XML from code is a very common development task. There are a multitude of ways it can be accomplished. Recently, at a client, we needed to generate an XML message which had to conform to a rather complicated XML schema. We already had an object model that worked well with our code base. We considered using XML binding API's like:
Each of these had its own limitations which reduced their feasibility within our application. Next we considered hand-coding the XML directly with API's like:
The amount of code required to create an XML document with these API's was excessive. Code like this was not fun to write nor easy to follow.

So we decided to take a different approach and use a templating engine, specifically FreeMarker. Using FreeMarker to generate the XML response messages turned out to be a great decision. This is a list of some of the advantages we have noticed:
  1. The FreeMarker template we wrote to create the XML response message is an XML document. This simple fact should not be overlooked.
  2. Easy to integrate into any application. Very little code was required to utilize FreeMarker in our application.
  3. Excellent performance.
  4. The built-in functionality that FreeMarker provides is very powerful.

Tutorials for Waffle

I have been spending my free time updating Waffle with functionality and documentation. Two tutorials have been added to the Waffle web site which should provide a good overview of how to use Waffle and what makes it different.

The examples in the tutorials show how to use Waffle with JSP's. This was done based on feedback I have had when talking about Waffle with developers. At this point you should get latest Waffle code directly from subversion and build it with Maven 2.0.

I would appreciate any comments or feedback you could offer.