1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
private static void generateStringXML(Document _xmlDoc) throws IOException {
XMLSerializer serializer = null;
OutputFormat outFormat = null;
String result = null;
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
// OutputFormat
outFormat = new OutputFormat();
outFormat.setEncoding("UTF-8");
outFormat.setVersion("1.0");
outFormat.setIndenting(true);
outFormat.setIndent(4);
// Serializer
serializer = new XMLSerializer(os, outFormat);
serializer.setOutputFormat(outFormat);
serializer.serialize(_xmlDoc);
// On récupère le resultat
result = new String(os.toByteArray());
os.close();
FileWriter fichier = new FileWriter("resultat.xml");
fichier.write(result);
fichier.close();
} catch (IOException e) {
throw e;
}
} |
Partager