When talking about object marshalling in most of the Java-XML data binding APIs, it has been said that the the XML file is recreated from the user defined classes from memory? I’m quite confusing about saying (user defined classes from memory). I know using reflection will help to get the class names and/or fields in case of need for implementing the marshalling process, but how the data (values for the elements or attributes) can be accessed?
Is there any one can explain this process a little?
thanks
You can access them using reflection. Reflection doesn’t returns just the name but the value that a field hold for example.
A simple example could be obtained with the following code:
This code would print out:
As you can see the values of each field is accessed using method
Field.get(Object). You can find more out here.