Catch TransformerException : Transformer « XML « Java Tutorial






import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.Templates;
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.transform.stream.StreamSource;

public class Main {
  public static void xsl(String inFilename, String outFilename, String xslFilename) {
    try {
      TransformerFactory factory = TransformerFactory.newInstance();
      Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
      Transformer xformer = template.newTransformer();
      Source source = new StreamSource(new FileInputStream(inFilename));
      Result result = new StreamResult(new FileOutputStream(outFilename));
      xformer.transform(source, result);
    } catch (FileNotFoundException e) {
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
      SourceLocator locator = e.getLocator();
      int col = locator.getColumnNumber();
      int line = locator.getLineNumber();
      String publicId = locator.getPublicId();
      String systemId = locator.getSystemId();
    }
  }
}








33.11.Transformer
33.11.1.Source for the JAXP Transformation Application
33.11.2.Source for Transforming DOM Node to HTML with JAXP
33.11.3.Catch TransformerException
33.11.4.Transforming an XML File with XSL into a DOM Document
33.11.5.Applying XSLT Stylesheets
33.11.6.Create an XML file and attach an XSL
33.11.7.And now to attach an XSL
33.11.8.Formatting an XML file using Transformer