FreeMarker Build XML

FreeMarker Build XML

I always prefer Java template, if any kind of predefined data structure need to be build. For example if you want to send email to somebody in HTML format with style and color as you have seen in this tutorial using Apache velocity template or if you have to create predefined XML file with dynamic data. Here I will show you how you can iterate java object (Peerson) and dynamically create XML file from FreeMarker template.

  • Project structure:

FreeMarker Build XML

  • pom.xml:

  • BuildXMLTemplate.ftl

  • Person.java – This is main class where we will store all XML data in list and dynamically replace its value to the template and create XML file.

  • FreeMarkerGenrateXMLFromObject.java:

  • Output:

FreeMarker Build XML

FreeMarker Build XML

  • For more details please visit FreeMarker official tutorial here

download  Download Project:  FreeMarkerCreateXMLFile

Leave a Reply

Your email address will not be published. Required fields are marked *