Have an extended Java app which does a lot of modifications including merging xml files. This is done using dom classes and seems to work fine. In the end I want to format the resultant xml so that it is more easily read and store as a String. Started out doing this with dom also, but it puts a limit on the size of the files I can format.
Current code is:
public String parseToString(Node node) {
Transformer transformer = null;
StringBuffer buffer = null;
try {
Transformer = TransformerFactory.newInstance().new Transformer();
--- set some OutputProperties ---
StringWriter stringWriter = new StringWriter(512);
transformer.transform(new DOMSource(node), new StreamResult(stringWriter));
buffer = stringWriter.getBuffer();
stringWriter.close();
--- catch phrases ---
return(buffer.toString());
}
My understanding is that to use SAX I need to replace "new DOMSource()" with "new StreamSource()", but to do this I need to convert the node (actually the complete document) to a string. What is the easiest way to do that without eating up more memory?