Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Out of memory when using transform function on huge xml

 
Sivakumar Bala
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic