问题
It's the first time I'm using stackoverflow and I don't speak English perfectly so be nice please.
I'm using Jaxb in append mode like that
for (Document330 document : documents){
JAXBContext jContext = JAXBContext.newInstance(Document330Xml.class);
Marshaller m = jContext.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(document, fos);
}
And I have an output file like that:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT>
<MAILING>
<REF>M584</REF>
<LIBELLE>Mail Test 1</LIBELLE>
</MAILING>
</DOCUMENT>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT>
<MAILING>
<REF>M585</REF>
<LIBELLE>Mail Test 2</LIBELLE>
</MAILING>
</DOCUMENT>
but I want something like that :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENTS>
<DOCUMENT>
<MAILING>
<REF>M584</REF>
<LIBELLE>Mail Test 1</LIBELLE>
</MAILING>
</DOCUMENT>
<DOCUMENT>
<MAILING>
<REF>M585</REF>
<LIBELLE>Mail Test 2</LIBELLE>
</MAILING>
</DOCUMENT>
</DOCUMENTS>
But it is possible that I have many XML. So I do not think the Unmarshaller is the best solution
Thanks for reading me
回答1:
If I remind correctly, you need to create a Documents330Xml
class, which can be marshalled (you can have a look at your Document330Xml
class for reference). This class needs a list of Document330Xml
as field.
If you then marshall the Documents330Xml
class, you should get the desired XML.
来源:https://stackoverflow.com/questions/49858160/merge-multiple-files-with-jaxb