1 16 19 import java.io.FileNotFoundException ; 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 23 import java.util.Properties ; 24 25 import javax.xml.parsers.ParserConfigurationException ; 26 import javax.xml.transform.Transformer ; 27 import javax.xml.transform.TransformerConfigurationException ; 28 import javax.xml.transform.TransformerException ; 29 import javax.xml.transform.TransformerFactory ; 30 import javax.xml.transform.stream.StreamResult ; 31 import javax.xml.transform.stream.StreamSource ; 32 33 import org.xml.sax.SAXException ; 34 35 36 44 public class JAXPTransletOneTransformation 45 { 46 public static void main(String argv[]) 47 throws TransformerException , TransformerConfigurationException , IOException , SAXException , 48 ParserConfigurationException , FileNotFoundException 49 { 50 String key = "javax.xml.transform.TransformerFactory"; 54 String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; 55 Properties props = System.getProperties(); 56 props.put(key, value); 57 System.setProperties(props); 58 59 String xslInURI = "todo.xsl"; 60 String xmlInURI = "todo.xml"; 61 String htmlOutURI = "todo.html"; 62 try 63 { 64 TransformerFactory tFactory = TransformerFactory.newInstance(); 67 Transformer transformer = tFactory.newTransformer(new StreamSource (xslInURI)); 68 transformer.transform(new StreamSource (xmlInURI), 70 new StreamResult (new FileOutputStream (htmlOutURI))); 71 System.out.println("Produced todo.html"); 72 } 73 catch (Exception e) 74 { 75 System.out.println(e.toString()); 76 e.printStackTrace(); 77 } 78 } 79 } 80 | Popular Tags |