permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Out of memory when using transform function on huge xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Out of memory when using transform function on huge xml" Watch "Out of memory when using transform function on huge xml" New topic
Author

Out of memory when using transform function on huge xml

Sivakumar Bala
Greenhorn

Joined: Apr 06, 2005
Posts: 2
Hi All

I trying to use an 500MB XML file in the transform method and getting out.of memory exception.

Is there any limit in the file size that can be used with transform.

Below is the function doing the job.

public void transform(String inXml, String inXslt, String outXml, Map params)
throws ValidationException , IOException {
LOG.info("Transform source XML file '" + inXml
+ "' to destination file '" + outXml + "' using XSLT file '"
+ inXslt + "'");

try {
// Instantiate a TransformerFactory
TransformerFactory tFactory = TransformerFactory.newInstance();

// Use the TransformerFactory to process the stylesheet source
// and generate a Transformer.
//Transformer transformer = tFactory.newTransformer(new FileIinXslt);
//Transformer transformer = tFactory.newTransformer(new StreamSource(this.getRules(inXslt)));
Transformer transformer = tFactory.newTransformer(new StreamSource(new File(inXslt)));
// set parameters
if (params != null && !params.isEmpty()) {
for (Iterator itr = params.entrySet().iterator(); itr.hasNext();) {
Map.Entry entry = (Map.Entry) itr.next();
transformer.setParameter((String) entry.getKey(), entry
.getValue());
}
}

StreamSource source = new StreamSource(inXml);
StreamResult result = new StreamResult(outXml);

String sourceXml = inXml;
transformer.setParameter("sourceXml", sourceXml);
ValidationErrorsCollector errorsCollector = new ValidationErrorsCollector(
maxValidationErrors);
XslValidationHandler.putErrorsCollector(sourceXml, errorsCollector);

// Use the Transformer to transform an XML Source and send the
// output to a Result object.
try {
transformer.transform(source, result);

if (errorsCollector.hasErrors()) {
LOG.error(TRANSFORMATION_ERROR_MSG);
throw new ValidationException(TRANSFORMATION_ERROR_MSG,
errorsCollector);
}
}
catch (TransformerException e) {
LOG.error(TRANSFORMATION_ERROR_MSG + ": " + e.getMessage());
throw new ValidationException(TRANSFORMATION_ERROR_MSG,
errorsCollector);
}
}
catch (TransformerConfigurationException e) {
LOG.error(TRANSFORMATION_ERROR_MSG, e);
}
}

Please advice.

Cheers
Siva
[ March 01, 2007: Message edited by: Sivakumar Bala ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Out of memory when using transform function on huge xml
 
Similar Threads
Transforming XML using Xalan
XML Parsing
Loading XSL template from URL for transformation
java.lang.IllegalAccessException
No output from Servlet