I am using JAXB MOXy to map my java objects to XML. Up until now I have only ever needed to convert 1 object at a time and that word fine. So my output XML looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<NotificationTemplateXML template-id="1">
<template-subject>Test Subject</template-subject>
<template-text>Test Text</template-text>
</NotificationTemplateXML>
What I am trying to do now is to have multiple iterations of the object saved into the same XML file so it looks something like this
<?xml version="1.0" encoding="UTF-8"?>
<NotificationTemplateXML template-id="1">
<template-subject>Test Subject</template-subject>
<template-text>Test Text</template-text>
</NotificationTemplateXML>
<NotificationTemplateXML template-id="2">
<template-subject>Test Subject</template-subject>
<template-text>Test Text</template-text>
</NotificationTemplateXML>
<NotificationTemplateXML template-id="3">
<template-subject>Test Subject</template-subject>
<template-text>Test Text</template-text>
</NotificationTemplateXML>
My object mapping looks like this:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="NotificationTemplateXML")
public class NotificationTemplate {
@XmlAttribute(name="template-id")
private String templateId;
@XmlElement(name="template-subject")
private String templateSubject;
@XmlElement(name="template-text")
private String templateText;
Assuming I have a list of Type 'NotificationTemplate' can I simply marshall the list? Will that produce a single xml file with each of the NotificationTemplate objects as a separate 'XML object'?
NB. Likewise when I Unmarshall the XML file am I expecting to produce a list of Type 'NotificationTemplate'?