dimanche 2 août 2015

Reading Transformer result line by line (Java)

I'm using Transformer to prettify and to insert indentation to an XML which is originally one big line. Here is my code:

BufferedWriter br = null;
Source xmlInput = new StreamSource(inputSR);
StringWriter stringWriter = new StringWriter();
StreamResult xmlOutput = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", 2);
Transformer transformer = transformerFactory.newTransformer(); 
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(xmlInput, xmlOutput);

How can I write the xmlOutput to a file, line by line (without loading the whole string to the memory)?

Aucun commentaire:

Enregistrer un commentaire