Example usage for javax.xml.transform TransformerFactory newInstance

List of usage examples for javax.xml.transform TransformerFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.transform TransformerFactory newInstance.

Prototype

public static TransformerFactory newInstance() throws TransformerFactoryConfigurationError 

Source Link

Document

Obtain a new instance of a TransformerFactory .

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    StreamSource source = new StreamSource(args[0]);
    StreamSource stylesource = new StreamSource(args[1]);

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(stylesource);

    StreamResult result = new StreamResult(System.out);
    transformer.transform(source, result);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    StreamSource xmlFile = new StreamSource(new File(args[0]));
    StreamSource xsltFile = new StreamSource(new File(args[1]));
    TransformerFactory xsltFactory = TransformerFactory.newInstance();
    Transformer transformer = xsltFactory.newTransformer(xsltFile);

    StreamResult resultStream = new StreamResult(System.out);
    transformer.transform(xmlFile, resultStream);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Source xslSource = new StreamSource(Main.class.getResourceAsStream("test.xsl"));
    Source xmlSource = new StreamSource(Main.class.getResourceAsStream("test.xml"));

    Transformer transf = TransformerFactory.newInstance().newTransformer(xslSource);

    StreamResult transformedXml = new StreamResult(System.out);
    transf.transform(xmlSource, transformedXml);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Document doc = null;/* ww w  .j  a va2 s  . c  o  m*/
    XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(System.out);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.transform(new DOMSource(doc), new StAXResult(writer));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    TransformerFactory factory = TransformerFactory.newInstance();
    Templates template = factory.newTemplates(new StreamSource(new FileInputStream("xsl.xlt")));
    Transformer xformer = template.newTransformer();
    Source source = new StreamSource(new FileInputStream("in.xml"));
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.newDocument();
    Result result = new DOMResult(doc);
    xformer.transform(source, result);//  w w  w .  j av  a 2  s.  com
}

From source file:JAXPTransform.java

public static void main(String args[])
        throws TransformerConfigurationException, TransformerException, FileNotFoundException {

    TransformerFactory factory = TransformerFactory.newInstance();

    StreamSource stylesheet = new StreamSource(args[1]);
    StreamSource xmlDoc = new StreamSource(args[0]);
    StreamResult result = new StreamResult(new FileOutputStream(args[2]));

    Transformer transFormer = factory.newTransformer(stylesheet);

    transFormer.transform(xmlDoc, result);

}

From source file:Transform2.java

public static void main(String[] args) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new File("r.xml"));
    Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource("program.xsl"));
    JDOMResult out = new JDOMResult();
    transformer.transform(new JDOMSource(document), out);
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.output(out.getDocument(), new FileWriter("JDOMAlteredRichard.html"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Document doc = null;/*from  ww  w. j ava 2  s.  co  m*/
    String filename = "name.xml";

    Source source = new DOMSource(doc);

    File file = new File(filename);
    Result result = new StreamResult(file);

    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.transform(source, result);
}

From source file:MainClass.java

public static void main(String argv[]) throws Exception {
    Properties props = System.getProperties();
    props.put("javax.xml.transform.TransformerFactory", "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
    System.setProperties(props);/* w w  w  .  ja v  a  2  s  .  co m*/
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Templates translet = tFactory.newTemplates(new StreamSource("OrderProcessing.xslt"));

    Transformer transformer = translet.newTransformer();

    transformer.transform(new StreamSource("CustomerOrders.xml"),
            new StreamResult(new FileOutputStream("SortedOrders.html")));

    transformer.transform(new StreamSource("CustomerOrders1.xml"),
            new StreamResult(new FileOutputStream("SortedOrders1.html")));

}

From source file:XMLTransform.java

public static void main(String[] args) throws Exception {
    System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    XMLReader reader = parser.getXMLReader();
    TransformerFactory factory = TransformerFactory.newInstance();
    System.out.println(factory);//from w w  w  .  j a  v a  2  s.co  m
    Transformer transformer = factory.newTransformer(new StreamSource("./xsl/books-sql.xsl"));
    transformer.setParameter("user", "root");
    transformer.setParameter("password", "123456");
    transformer.transform(new StreamSource("./xml/books.xml"), new StreamResult(System.out));
}