How to reconstruct a Java sub class from XML

I will have a XML with following structure,\[code\]<xml><Header><Type>..</Type>...</Header><Data>...</Data></xml>\[/code\]Based on the \[code\]<Type>\[/code\] value, the \[code\]<Data>\[/code\] element will have different elements. For e.g\[code\]<xml><Header><Type>Int</Type></Header><Data><Integer>10<Integer></Data></xml><xml><Header><Type>Str</Type></Header><Data><String>JAXB Test</String></Data></xml>\[/code\]The Java classes will be\[code\]class TypeEntity { }class IntEntity extends TypeEntity { }class StrEntity extends TypeEntity { }\[/code\]I want to use JAXB to parse the xml and create the sub classes accordingly. How I can do this? Please help me.EDIT: Actually I will get these XML from a web service. After receiving I need to convert these as Java classes. Right now I am using DOM parser to identify the Type and instantiating the Java sub classes. I want to know is there any better way of doing this. Thanks
 
Back
Top