xstream을 보면 선적 서류 비치, 그들은 당신이 XML Prolog를 직접 추가해야한다고 분명히 말합니다.
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).
다음 코드가 작동해야합니다. 코드의 대부분을 제거 했으므로 다시 넣어야합니다. 목적은 단지 당신에게 대략적인 일을하는 예를 제공하는 것입니다.
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
}
}