I have the following XML structure, which is modelling a single concept across multiple XML elements. This format is not in my control.
<Output>
<Wrapper>
<Channel>
<id>1</id>
<type>x</type>
</Channel>
<Channel>
<id>2</id>
<type>y</type>
</Channel>
<ChannelName>
<id>1</id>
<name>Channel name</name>
</ChannelName>
<ChannelName>
<id>2</id>
<name>Another channel name</name>
</ChannelName>
</Wrapper>
</Output>
I want to model this in a database that I do have control over and can have a more simple Channel
table with id
, type
and name
fields. Therefore I would like to unmarshal into a single List<Channel>
on the Wrapper
class.
Can this be done with @Xml...
annotations automatically? I am currently using JAXB to unmarshal into separate @XmlElement(name="Channel")
and @XmlElement(name="ChannelName")
class lists and then post-processing the transient ChannelName/name
on the Channel
but I am thinking there must be an easier automated way to map these elements. Or is it a job for XSLT?
It might help to know that the XML is coming in as an HTTP file POST file and I'm using Spring 3, Java and Hibernate. I'm hoping something in EclipseLink JAXB (MOXy) might help :)