How to create a customised XML document using smooks?



I want to convert an object graph to a XMl document using smooks. However I don't want tight coupling with the object graph and the generating xml structure so I need to have a mapping file or want to use annotations. The java to xml example given in the smooks documentation is really limited and I can't find a proper way to do this.


This is my object structure ;



Parent Class { --------> <Root>
ParentFieldOne; ---> <SomeFieldOne>
ParentFieldTwo; ----> <SomeFieldTwo>
List<ChildObject> ----> <Dependents>
}

ChildClass { ----> <Child>
ChildFieldOne; ---> <SomeChildFieldOne>
ChildFieldTwo; ---> <SomeChildFieldTwo>
}


So the resulting XMl would be like this;



<Root>
<SomeFieldOne></SomeFieldOne>
<SomeFieldTwo></<SomeFieldTwo>
<Dependents>
<Child>
<SomeChildFieldOne></SomeChildFieldOne>
<SomeChildFieldTwo></SomeChildFieldTwo>
</Child>
</Dependents>
</Root>


PS : I don't want to use freemarker thought this is possible using it. I guess using a template mechanism for a task like this would be inefficient.


No comments:

Post a Comment