Please suggest me how to do the following utility in java,
- Want to create the generic java class to generate the XML with JDOM.
- Class is capable enough to generate the any xml structure in runtime depends on parameter pass -- How?
For example, In my module I need to create the XML which having 3 different child with one root i.e.
<Child> <A> This is normal text </A> <B> This is normal text </B> <C> This is normal text </C> </Child>
But in another module we required another XML file which having the 10 child with some attribute.
- So we decided to go for generic XML utility which generate the XML file in runtime in specific folder.
- Utility will help us to avoid the redundant code in the application and easy to manage as well...
Please help your friend...
Thanks Gladiator
You can do via XStream like this:
If you have control over the classes which you are going to convert into XML then I would suggest to have an interface something like
XMLConvertable
with some structure likeIn that case you don't need to send last three parameters in the above method just get it from the
objectToBeConverted
and also it makes more sense as every object in the system can declare itself whether it can be converted to XML or not.