How to prevent outOfMemoryErrors when performing XSLT transformations
Hello,
We frequently have out of memory errors when our XSLT transformations run depending on the size of our source xml documents.
Here is the code that causes the above error to occur:
System.out.println("XSLT transformation running...");
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(args[2]));
transformer.transform(new StreamSource(args[0]),new StreamResult(new FileOutputStream(args[3])));
System.out.println("XSLT transformation complete!");
and the imports
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
We cannot increase memory on our servers nor can we reduce the size of our source documents. Is there a way to prevent this kind of errors from occurring or reduce memory footprint? (even though if it means having the transformation taking longer...)
Any clue welcome,
Thanks,
Julien.

