Si vous regardez le Xstream Documentation, ils déclarent clairement que vous devez ajouter le Prolog XML vous-même:
Why does XStream not write an XML declaration?
XStream is designed to write XML snippets, so you can embed its output into
an existing stream or string. You can write the XML declaration yourself into
the Writer before using it to call XStream.toXML(writer).
Le code suivant devrait fonctionner. J'ai supprimé la plupart de votre code, vous devez donc le remettre. Le but est simplement de vous donner un exemple de travail difficile:
private static void serializeData(Object diagData) throws Exception {
XStream xstream = new XStream();
xstream.processAnnotations(DiagData.class);
FileOutputStream fileOutputStream = null;
Writer writer = new PrintWriter(new File(your file));
CompactWriter compactWriter = new CompactWriter(writer);
try {
writer.write(your xml prolog);
writer.write(your stylesheet);
xstream.marshal(diagData, compactWriter);
} catch (FileNotFoundException e1) {
} catch (Exception e) {
} finally {
release resources
}
}