I've asked this question before:
Generate XML from class
I want to do this with Java.
Can I do the same with Java via attributes?
or there is a framework that I can use for this purpose.
XStream will allow you to represent any class as XML. You can check here for an example.
JAXB might be what you want. This is pretty common. You just add some annotations to your properties and any instance of this class can be serialized / deserialized to XML.
I prefer XStream, but there is also Castor XML