I am trying to ummarshal XML file that contains multiple objects, but not a List of Objects. I am not storing a List because I need to append single objects quite frequently.
Here is what the generated through marshalling XML looks like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message>
<datetime>2015-03-26T10:33:52.540+02:00</datetime>
<id>1</id>
<rawChat>
<members_ids>1</members_ids>
<members_ids>2</members_ids>
</rawChat>
<sender>
<id>1</id>
<username>teso</username>
</sender>
<text>hello</text>
</message>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message>
<datetime>2015-03-26T10:38:59.576+02:00</datetime>
<id>2</id>
<rawChat>
<members_ids>1</members_ids>
<members_ids>2</members_ids>
</rawChat>
<sender>
<id>1</id>
<username>teso</username>
</sender>
<text>msg2</text>
</message>
And here is how I have marshalled it:
public void marshal(Message message) {
try {
JAXBContext jc = JAXBContext.newInstance(Message.class);
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(message, new FileOutputStream("messages.xml", true));
m.marshal(message, System.out);
} catch (JAXBException | IOException e) {
e.printStackTrace();
}
}
I need to unmarshall all the messages. Could you please give me some ideas how to do it?