Code example for SAXSource

0
   * @throws IOException If the file cannot be opened. 
   * @throws TransformerException If processing the XSL script causes an error. 
   */ 
  public static void xmlToHTML(File xml, File html, URL xsl) throws ParserConfigurationException, 
      SAXException, IOException, TransformerException { 
    Source source = new SAXSource( 
        new InputSource(new BufferedInputStream(new FileInputStream(xml)))); 
    // Create output file 
    Result result = new StreamResult(html); 
    // Transformer configuration 
    TransformerFactory transformerFactory = TransformerFactory.newInstance(); 
    StreamSource genresource = new StreamSource(xsl.openStream()); 
    Transformer transformer = transformerFactory.newTransformer(genresource); 
    transformer.setOutputProperty(OutputKeys.METHOD, "html"); 
    // Transformation 
    transformer.transform(source, result); 
  } 
}