I want to unmarshal a xml file containing a collection of data, like this
<Persons>
<Person>Jim</Person>
<Person>Tom</Person>
</Persons>
We know this can be done with two classess: Persons, Person using Castor , JAXB, or other frameworks.
But how to do without writing a collection class Persons ?
You could use a StAX parser and do something like the following with any JAXB implementation (Metro, EclipseLink MOXy, Apache JaxMe, etc):
input.xml
System Output
Person
JAXB:
unmarshaller.unmarshal(node, Person.class)
There are also advanced techniques with programmaticaly created mappings.
Look for a way to tell Castor that you'd like it to generate a
java.util.List
of Person instances.http://www.castor.org/how-to-map-a-list-at-root.html