How to use inner loops in Apache Velocity to parse XML

Hits

New Member
I am going to develop a eclipse plugin to generate simple Java source codes.Initially I need to convert a XML file to Java Class code. I found Apache Velocity from internet and now I am playing with some simple stuffs.This is my input XML file:\[code\]<?xml version= "1.0" encoding= "UTF-8" ?> <Content> <Class name= "Customer" acc_modif="public"> <attributes> <attribute attribute_type= "String" attribute_name= "studentName" attribute_acc_modifer="public"/> <attribute attribute_type= "int" attribute_name= "age" attribute_acc_modifer="public"/> </attributes><constructors> <constructor con_acc_modifer="public" con_name="Student"> <para para_type="String" para_name="studentName"/> <para para_type="int" para_name="age"/> </constructor> <constructor con_acc_modifer="public" con_name="Student"> <para para_type="String" para_name="studentName"/> <para para_type="int" para_name="age"/> </constructor></constructors></Class> </Content>\[/code\]And this is my template file:\[code\]## class .vm ##apachi-3import java.util.*; $class.acc_modif class $class.name { #foreach ( $att in $class.attributes ) $att.attribute_acc_modifer $att.attribute_type $att.attribute_name; #end#foreach ( $con in $class.constructors ) $con.con_acc_modifer $con.con_name ( $con.para_type $con.para_name ) { ## Not working :(} #end }\[/code\]And the output was like this:\[code\]import java.util.*; public class Customer { public String studentName; public int age; public Student ( $con.para_type $con.para_name ) { } public Student ( $con.para_type $con.para_name ) { } }\[/code\]Student constructors are not working. I think I need to use another loop inside brackets instead of "$con.para_type $con.para_name"But I don't know how to use another loop here (i am a noob of Apache Velocity).
Velocity Gurus please help me!
 
Back
Top